3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function any($elements, Clousure $x){ foreach($elements as $element){ if($x($element)) return true; } return false; } function all($elements, Clousure $x){ foreach($elements as $element){ if(!$x($element)) return false; } return true; } function minimum($of) { return function($el) use ($of){ if($el < $of) return true; return false; }; } echo "any x <- [1, 2, 3, 4, 5] | < 5" . PHP_EOL; if(any(array(1, 2, 3, 4, 5), minimum(5))) { echo "true" . PHP_EOL; } else { echo "false" . PHP_EOL; }; echo "all x <- [1, 2, 3, 4] | < 5" . PHP_EOL; if(all(array(1, 2, 3, 4), minimum(5))) { echo "true" . PHP_EOL; } else { echo "false" . PHP_EOL; };
based on FsVkD
Output for 7.0.0 - 7.2.0
any x <- [1, 2, 3, 4, 5] | < 5 Fatal error: Uncaught TypeError: Argument 2 passed to any() must be an instance of Clousure, instance of Closure given, called in /in/UUe6i on line 29 and defined in /in/UUe6i:3 Stack trace: #0 /in/UUe6i(29): any(Array, Object(Closure)) #1 {main} thrown in /in/UUe6i on line 3
Process exited with code 255.
Output for 5.3.22 - 5.6.28
any x <- [1, 2, 3, 4, 5] | < 5 Catchable fatal error: Argument 2 passed to any() must be an instance of Clousure, instance of Closure given, called in /in/UUe6i on line 29 and defined in /in/UUe6i on line 3
Process exited with code 255.