$arr = array(1); $a = & $arr; $arr2 = $arr; $arr2++; echo $arr,$arr2; // Output 2,2
Can you please help me how is it possible?
Note, however, that references inside arrays are potentially dangerous. Doing a normal (not by reference) assignment with a reference on the right side does not turn the left side into a reference, but references inside arrays are preserved in these normal assignments. This also applies to function calls where the array is passed by value.
/* Assignment of array variables */ $arr = array(1); $a =& $arr; //$a and $arr are in the same reference set $arr2 = $arr; //not an assignment-by-reference! $arr2++; /* $a == 2, $arr == array(2) */ /* The contents of $arr are changed even though it's not a reference! */