3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = ['one', 'two', 'three', 'four', 'five']; echo 'Current value: ' . current($arr) . "\n"; foreach ($arr as $a) { if ($a === 'three') break; } echo 'Did it change? ' . current($arr) . "\n"; function withRef(array &$arr): void { foreach ($arr as $a) { if ($a === 'three') break; } } withRef($arr); echo 'What about now? ' . current($arr) . "\n";
Output for 7.4.33, 8.1.28 - 8.1.29, 8.2.18 - 8.2.20, 8.3.5 - 8.3.8
Current value: one Did it change? one What about now? one
Output for 5.5.21
Parse error: syntax error, unexpected ':', expecting '{' in /in/LAbQA on line 14
Process exited with code 255.

preferences:
52.63 ms | 401 KiB | 16 Q