3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * @param array $numbers * * @return array */ function find_even(array $numbers) { if (count($numbers) === 0) { return []; } if (count($numbers) === 1) { return has_even($numbers) ? $numbers : []; } list($left, $right) = array_chunk($numbers, ceil(count($numbers) / 2)); $left = has_even($left) ? $left : []; $right = has_even($right) ? $right : []; $leftResult = (count($left) > 1) ? find_even($left) : $left; $rightResult = (count($right) > 1) ? find_even($right) : $right; return array_merge($leftResult, $rightResult); } /** * @param array $numbers * * @return bool */ function has_even(array $numbers) { echo join(' ', $numbers) . PHP_EOL; foreach ($numbers as $number) { if ($number % 2 === 0) { return true; } } return false; } $numbers = [1, 2, 3, 7, 5, 7, 1, 3, 4, 9, 7, 3, 5, 7, 9]; echo join(' ', $numbers) . PHP_EOL . PHP_EOL; echo PHP_EOL . join(' ', find_even($numbers)) . PHP_EOL;
Output for 5.4.0 - 7.2.0
1 2 3 7 5 7 1 3 4 9 7 3 5 7 9 1 2 3 7 5 7 1 3 4 9 7 3 5 7 9 1 2 3 7 5 7 1 3 1 2 3 7 1 2 4 9 7 3 5 7 9 4 9 7 3 4 9 2 4
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/EQtXT on line 10
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/EQtXT on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/EQtXT on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/EQtXT on line 8
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/EQtXT on line 8
Process exited with code 255.