First, when the PHP array variable $arr assigned to another variable $one, this is the array variable $arr the entire copy to $one, even if $arr is a multidimensional array.
Cases:
$arr=Array(1, 2, 3,Array(' One ', ' both '));$one=$arr;
#output original Array $arrPrint_r($arr);#Array ([0] = 1 [1] = 2 [2] = + 3 [3] = = Array ([0] = = one [1] = both))
#output New Array $one
Print_r($one);#Array ([0] = 1 [1] = 2 [2] = + 3 [3] = = Array ([0] = = one [1] = both))
#modifies the original array $arr, and outputs$arr[0] = 4; $arr[3] [1] = ' three ';Print_r($arr); #Array ([0] = 4 [1] = 2 [2] = 3 [3] = = Array ([0] = = one [1] = three))
#output new Array $onePrint_r($one); #Array ([0] = 1 [1] = 2 [2] = + 3 [3] = = Array ([0] = = one [1] = both))
As can be seen from the example, modifying the value of the original array does not affect the new array
When the PHP array variable $arr uses a reference to assign to another variable $one, the array variable $arr is not copied to the $one, but the reference to the array is assigned to $one, that is, two variables point to the same array
Cases:
$arr=Array(1, 2, 3,Array(' One ', ' both '));$one= &$arr;#output original Array $arrPrint_r($arr);#Array ([0] = 1 [1] = 2 [2] = + 3 [3] = = Array ([0] = = one [1] = both))#output new Array $onePrint_r($one);#Array ([0] = 1 [1] = 2 [2] = + 3 [3] = = Array ([0] = = one [1] = both))#modifies the original array $arr, and outputs$arr[0] = 4; $arr[3] [1] = ' three ';Print_r($arr);#Array ([0] = 4 [1] = 2 [2] = 3 [3] = = Array ([0] = = one [1] = three))#output new Array $onePrint_r($one);#Array ([0] = 4 [1] = 2 [2] = 3 [3] = = Array ([0] = = one [1] = three))
As can be seen from the example, the value of the original array is modified, and the new array value is changed.
The above code, is written directly in the blog, if directly copied paste into the sublime text3 inside, execution will error.
Puzzled half a day, only to find that the code format has a space reason. Probably because it is written directly with this blog plugin. It works correctly after you modify the format in sublime Text3.
Deep copy and reference assignment of PHP arrays