只是好奇是否这样做
$this->item['foo'] = $this->action(3);
$this->item['bar'] = $this->action(1);
$this->item['baz'] = $this->action(1);
和做的一样
$this->item = ($this->item +
[
'foo' => $this->action(3),
'bar' => $this->action(1),
'baz' => $this->action(1),
]);
如果您能解释为什么/为什么我会很感激
如果$this->item
已经具有您指定的任何键,则它们并不等效。从文档中:
对于两个数组中都存在的键,将使用左侧数组中的元素,而右侧数组中的匹配元素将被忽略。
您可以通过切换参数顺序来解决此问题:
$this->item = (
[
'foo' => $this->action(3),
'bar' => $this->action(1),
'baz' => $this->action(1),
] + $this->item);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句