3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function array_limit($array, $limit) { // Generators are only supported in PHP 5.5.0 and above echo ">".PHP_VERSION."<"; if (version_compare(PHP_VERSION, '5.5.0', '<')) { // Emulate the generator with array_slice() return array_slice($array, 0, $limit, true); } else { // Cycle through the array foreach ($array as $key => $value) { if (!$limit--) break; yield $key => $value; } } }
Output for 7.0.0 - 7.1.0
Output for 5.5.0 - 5.6.28
Fatal error: Generators cannot return values using "return" in /in/Ws4vQ on line 9
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$key' (T_VARIABLE) in /in/Ws4vQ on line 17
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/Ws4vQ on line 17
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_VARIABLE in /in/Ws4vQ on line 17
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Ws4vQ on line 17
Process exited with code 255.