3v4l.org

run code in 300+ PHP versions simultaneously
<?php function print_while_each($list) { while (list($key, $val) = each($list)) { echo $key, $val; if ($val == '2') { $list[] = 4; } } } function print_foreach($list) { foreach ($list as $key => $val) { echo $key, $val; if ($val == '2') { $list[] = 4; } } } function print_while_next($list) { $val = reset($list); while (!empty($val)) { $key = key($list); $val = current($list); echo $key, $val; if ($val == '2') { $list[] = 4; } $val = next($list); } } $list = array('1', '2', '3'); print_while_each($list); echo '<br>', PHP_EOL; print_foreach($list); echo '<br>', PHP_EOL; print_while_next($list); echo '<br>', PHP_EOL;
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Fatal error: Uncaught Error: Call to undefined function each() in /in/g77Ae:4 Stack trace: #0 /in/g77Ae(37): print_while_each(Array) #1 {main} thrown in /in/g77Ae on line 4
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /in/g77Ae on line 4 01122334<br> 011223<br> 01122334<br>
Output for 7.1.0 - 7.1.33, 7.3.32 - 7.3.33
01122334<br> 011223<br> 01122334<br>

preferences:
144.45 ms | 408 KiB | 5 Q