3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = array(0, 1, 2); $ref = &$a[2]; $b = $a; // Element [2] is not int(2) but &int(2) var_dump($a); // Updating $ref also updates $a[2], as expected $ref = 99; var_dump($a); // $b[2] is also &int(99), it references the same object as $a[2] and $ref var_dump($b); // Therefore we can do the same update by reference $b[2] = 1234; var_dump($a);
based on jK6fJ
Output for 5.3.18 - 7.2.0
array(3) { [0]=> int(0) [1]=> int(1) [2]=> &int(2) } array(3) { [0]=> int(0) [1]=> int(1) [2]=> &int(99) } array(3) { [0]=> int(0) [1]=> int(1) [2]=> &int(99) } array(3) { [0]=> int(0) [1]=> int(1) [2]=> &int(1234) }