3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_even(int $n): bool { if ($n < 0) { $n = abs($n); } return $n === 0 ? true : ($n === 1 ? false : (is_even($n - 2))); } for($i = -5; $i <= 12; $i++) { printf('is %d even? %s.%s', $i, is_even($i) ? 'yes': 'no', "\n"); }
based on 0Hnsp
Output for 7.2.0 - 7.2.32, 7.3.0 - 7.3.20, 7.4.0 - 7.4.8, 8.0.0alpha1 - alpha3
is -5 even? no. is -4 even? yes. is -3 even? no. is -2 even? yes. is -1 even? no. is 0 even? yes. is 1 even? no. is 2 even? yes. is 3 even? no. is 4 even? yes. is 5 even? no. is 6 even? yes. is 7 even? no. is 8 even? yes. is 9 even? no. is 10 even? yes. is 11 even? no. is 12 even? yes.