3v4l.org

run code in 300+ PHP versions simultaneously
<?php $result = []; function getNumsOdd(array $nums, array &$result) { foreach($nums as $key => $num) { if ($num % 2) { $result[$key] = $num; echo $num; yield; } } } $limit_documents = 2; $gen = getNumsOdd([1,3,4,5,6,7,8,9]); for($i = 0; $limit_documents >= $i && $gen->next(); ++$i); var_dump($result); /*foreach(getNumsOdd([1,3,4,5,6]) as $key => $num) { echo $key . '=>' . $num.PHP_EOL; }*/
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Fatal error: Uncaught ArgumentCountError: Too few arguments to function getNumsOdd(), 1 passed in /in/A0TbJ on line 14 and exactly 2 expected in /in/A0TbJ:3 Stack trace: #0 /in/A0TbJ(14): getNumsOdd(Array) #1 {main} thrown in /in/A0TbJ on line 3
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Fatal error: Uncaught ArgumentCountError: Too few arguments to function getNumsOdd(), 1 passed in /in/A0TbJ on line 14 and exactly 2 expected in /in/A0TbJ:3 Stack trace: #0 /in/A0TbJ(14): getNumsOdd(Array) #1 {main} thrown in /in/A0TbJ on line 3
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Fatal error: Uncaught TypeError: Argument 2 passed to getNumsOdd() must be of the type array, none given in /in/A0TbJ:3 Stack trace: #0 [internal function]: getNumsOdd(Array) #1 /in/A0TbJ(16): Generator->next() #2 {main} thrown in /in/A0TbJ on line 3
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.7 - 5.6.28
Catchable fatal error: Argument 2 passed to getNumsOdd() must be of the type array, none given in /in/A0TbJ on line 3
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Catchable fatal error: Argument 2 passed to getNumsOdd() must be of the type array, none given, called in /in/A0TbJ on line 14 and defined in /in/A0TbJ on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/A0TbJ on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/A0TbJ on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/A0TbJ on line 2
Process exited with code 255.

preferences:
307.4 ms | 401 KiB | 357 Q