3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(1, 1); $a = &$arr[0]; $a++; //'$a' and '$arr[0]' point to the same reference. echo '$arr:' . "\n"; var_dump($arr); echo '$a:' . "\n"; var_dump($a); echo PHP_EOL . PHP_EOL; $arr2 = $arr; $arr2[0]++; $arr2[1]++; //Even though you didn't assigned '$arr' to '$arr2' by reference, the first element keeps the reference to the original value. Now '$arr[0]', '$a' and '$arr2[0]' point all to the same reference. //But the second element won't change for the '$arr' array echo '$arr:' . "\n"; var_dump($arr); echo '$arr2:' . "\n"; var_dump($arr2);

preferences:
48.76 ms | 402 KiB | 5 Q