Just curious if doing this
$this->item['foo'] = $this->action(3);
$this->item['bar'] = $this->action(1);
$this->item['baz'] = $this->action(1);
is the same as doing
$this->item = ($this->item +
[
'foo' => $this->action(3),
'bar' => $this->action(1),
'baz' => $this->action(1),
]);
if you could explain why/why not I'd be appreciative
They're not equivalent if $this->item
already has any of the keys you're specifying. From the documentation:
for keys that exist in both arrays, the elements from the left-hand array will be used, and the matching elements from the right-hand array will be ignored.
You can resolve this by switching the order of arguments:
$this->item = (
[
'foo' => $this->action(3),
'bar' => $this->action(1),
'baz' => $this->action(1),
] + $this->item);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With