3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $a = array(1, 2, 3, 4, 5); foreach($a as $n) { echo "$n"; if ($n == 4) { echo '.'; $a = array_merge($a, array(6, 7)); } } echo "\n"; $a = array(1, 2, 3, 4, 5); foreach($a as $n) { echo "$n"; if ($n == 4) { echo '.'; $a[] = 6; $a[] = 7; } } echo "\n"; $a = array(1, 2, 3, 4, 5); foreach($a as $n) { echo "$n"; if ($n == 4) { echo '.'; array_push($a, 6); array_push($a, 7); } } echo "\n"; $a = array(1, 2, 3, 4, 5); foreach($a as $n) { echo "$n"; if ($n == 4) { echo '.'; array_push($a, 6, 7); } } echo "\n"; $a = array(1, 2, 3, 4, 5); foreach($a as $n) { echo "$n"; if ($n == 4) { echo '.'; array_push($a, array(6, 7)); } } echo "\n"; $a = array(1, 2, 3, 4, 5); $a = new ArrayObject($a); foreach($a as $n) { echo "$n"; if ($n == 4) { echo '.'; $a->append(6); $a->append(7); } } echo "\n";
based on KCl61
Output for 5.0.0 - 7.2.0
1234.5 1234.5 1234.5 1234.5 1234.5 1234.567
Output for 4.3.2 - 4.4.9
1234.5 1234.5 1234.5 1234.5 1234.5 Fatal error: Cannot instantiate non-existent class: arrayobject in /in/hOd5l on line 60
Process exited with code 255.
Output for 4.3.0 - 4.3.1
1234.5 1234.5 1234.5 1234.5 1234.5 Fatal error: Cannot instantiate non-existent class: arrayobject in /in/hOd5l on line 60