$arr = array(1);
$a = & $arr[0];
$arr2 = $arr;
$arr2[0]++;
echo $arr[0],$arr2[0];
// Output 2,2
您能帮我怎么可能吗?
最佳答案
/* Assignment of array variables */
$arr = array(1);
$a =& $arr[0]; //$a and $arr[0] are in the same reference set
$arr2 = $arr; //not an assignment-by-reference!
$arr2[0]++;
/* $a == 2, $arr == array(2) */
/* The contents of $arr are changed even though it's not a reference! */
关于php - PHP中的数组引用困惑,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12297239/