When you assign-by-value an array variable in PHP,

2019-09-20 13:28发布

It seems really inefficient that in PHP, when an array is assigned by value all of its internal elements are recursively copied to the new variable. Is this what really happens internally?

1条回答
你好瞎i
2楼-- · 2019-09-20 14:31

No, the internally array is not deep-copied on assignment. Consider the following snippet:

$a = array(111, 222, 333);
$b = $a;
$b[0] = 999;

If a picture is worth a thousand words, then here is what happens internally when arrays are assigned and then their array elements are modified:

enter image description here

查看更多
登录 后发表回答