3v4l.org

run code in 300+ PHP versions simultaneously
<?php function Y ($le) {return (function ($f) {return $f($f); })(function ($f) use ($le) {return $le(function ($x) use ($f) {return $f($f)($x); }); }); } $le = function ($factorial) {return function ($n) use ($factorial) {return $n < 2 ? $n : $n * $factorial($n - 1); }; }; $factorial = Y($le); echo $factorial(1) . PHP_EOL; // 1 echo $factorial(2) . PHP_EOL; // 2 echo $factorial(5) . PHP_EOL; // 120
Output for 7.1.25 - 7.1.30, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.26, 8.1.0 - 8.1.13
1 2 120

preferences:
66.93 ms | 410 KiB | 5 Q