Created
July 13, 2016 08:06
-
-
Save vamsiikrishna/511722a52f0596d0c5600cf1aa0e7c5c to your computer and use it in GitHub Desktop.
Factorial of a number using Closure in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$factorial = function($n) use (&$factorial) { | |
if($n <= 1) | |
return 1; | |
else | |
return $n * $factorial($n -1); | |
}; | |
echo $factorial(5).PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment