If you want $array2
to be a reference of $array1
then you do the same thing as with $x
.
$array2 = &$array1;
Now anything you change in either $array1
or $array2
is visible in both arrays since $array2
is just a reference to $array1
.
Update
Thinking about it, what you may be looking at is a way to change a value, but still have a full copy of the arrays. This is doable with an object.
$obj = new stdClass();
$array1 = array(1, 20);
$array1[1] = $obj;
$array1[1]->color = 22;
$array2 = $array1;
$array2[1]->color = 33;
echo $array1[1]->color; // prints 33
This is because objects are always copied by reference, whereas numbers and strings are copied as is.