3v4l.org

run code in 500+ PHP versions simultaneously
<?php /* TL;DR list($key, $callback) = each($callbacks); can be replaced with $key = key($callbacks); $callback = current($callbacks); next($callbacks); */ /* Original example */ $callbacks = [ 'key1' => 'value1', 'key2' => 'value2', ]; list($key, $callback) = each($callbacks); var_dump($key, $callback); // Verify which value $callbacks point to after each() has advanced the internal array pointer var_dump(current($callbacks)); /* Replacement example */ $callbacks = [ 'key1' => 'value1', 'key2' => 'value2', ]; $key = key($callbacks); $callback = current($callbacks); next($callbacks); var_dump($key, $callback); // Verify which value $callbacks point to after next() has advanced the internal array pointer var_dump(current($callbacks));
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.31, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
Fatal error: Uncaught Error: Call to undefined function each() in /in/DWYMt:19 Stack trace: #0 {main} thrown in /in/DWYMt on line 19
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.3.33, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /in/DWYMt on line 19 string(4) "key1" string(6) "value1" string(6) "value2" string(4) "key1" string(6) "value1" string(6) "value2"
Output for 7.3.32, 7.4.26
string(4) "key1" string(6) "value1" string(6) "value2" string(4) "key1" string(6) "value1" string(6) "value2"

preferences:
115.84 ms | 1547 KiB | 4 Q