3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a= []; $b = 'foo'; $c = 'bar'; $a[$b][$c][] = 1; echo "Assign to left-hand side:"; print_it($a,$b,$c); echo "Assign via byref call:"; byref($a[$b][$c]); print_it($a,$b,$c); function byref(&$x) { $x[]= 2; } function print_it($a,$b,$c) { echo "\n"; echo "\n" . json_encode($a); echo "\n" . json_encode($a[$b]); echo "\n" . json_encode($a[$b][$c]); echo "\n\n"; }
Output for 7.3.0 - 7.3.29, 7.4.0 - 7.4.21, 8.0.0 - 8.0.8
Assign to left-hand side: {"foo":{"bar":[1]}} {"bar":[1]} [1] Assign via byref call: {"foo":{"bar":[1,2]}} {"bar":[1,2]} [1,2]

preferences:
150.87 ms | 459 KiB | 5 Q