3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = [0, 1, 2]; $ref =& $array; // Necessary to trigger the old behavior foreach ($array as $k => &$val) { echo $val . ' '; if($k < 5 && !isset($array[$k+1])) $array[$k+1] = $val+1; } echo PHP_EOL . json_encode($array);
based on IZ2mv
Output for 7.0.0 - 7.2.0
0 1 2 3 4 5 [0,1,2,3,4,5]
Output for 5.4.0 - 5.6.28
0 1 2 [0,1,2,3]