Last active
August 29, 2015 14:17
-
-
Save smilesrg/59f5fdd706a7d66522c6 to your computer and use it in GitHub Desktop.
PHP Factorial calculation usng BC Math extension
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 | |
define('F_NUMBER', 25); | |
function factorial($in) { | |
// 0! = 1! = 1 | |
$out = '1'; | |
// Only if $in is >= 2 | |
for ($i = 2; $i <= $in; $i++) { | |
$out = bcmul($out, (string)$i); | |
} | |
return $out; | |
} | |
echo factorial(F_NUMBER); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment