function odd($x) { if ($x == 0) { return false; } else { return even($x - 1); } }
function odd() { return negate(even()); }
/** * */ function loop(array $bindings) { $args = func_get_args(); $exprs = rest($args); if (!even(count($bindings))) { throw new Exception('Bindings should be an array with an even number of values'); } }
<?php function even($var) { if ($var % 2 == 0) { return true; } else { return false; } } var_dump(even(6));
<?php // Simple variable that stores a function to return if the number is even $even = function ($number) { return $number % 2 ? null : $number; }; echo "Using first class functions the result is: " . $even(12) . "\n"; // Of course the prev example can be done imperative with a function as follows: function even($number) { return $number % 2 ? null : $number; } echo "Using a function the result is: " . even(12);