Is there any way to set a default value for a destructed array that doesn't have the specified index?
Similar to destructing an object in ES6, where if the passed object doesn't have the property (in the following example, the name
prop), it will have a default value:
const ({name = '', age}) => {
};
I'm currently destroying an array like the following:
// Inside my class
public function __construct(array $props) {
[ 'id' => $this->id, 'name' => $this->name ] = $props;
}
However, I want the 'id'
to be optional, so that $this->id
can pick up 0
as a default value when no 'id'
is passed.
This works for me: