$arr1 = array(1);
arr2 = $arr1;
$arr2[0]++;//$arr1[0]=1,$arr2[0]=2
But the following code:
$arr1 = array(1);
$a =& $arr1[0];
$arr2 = $arr1;
$arr2[0]++;//$arr1[0]=2,$arr2[0]=2
When I add $a
, the output is different! Why does this happen?
$arr1 = array(1);
arr2 = $arr1;
$arr2[0]++;//$arr1[0]=1,$arr2[0]=2
But the following code:
$arr1 = array(1);
$a =& $arr1[0];
$arr2 = $arr1;
$arr2[0]++;//$arr1[0]=2,$arr2[0]=2
When I add $a
, the output is different! Why does this happen?
@JakubMatczak Thanks for your professional response.But I still have some question.
$arr1 = array(1, 2);
$a =& $arr1;
$arr2 = $arr1;
$arr2[0]++;
$arr2[1]++;
Why the result of $arr1
is array(1, 2)
not array(2, 2)
?