Skip to content

Instantly share code, notes, and snippets.

@smilesrg
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smilesrg/59f5fdd706a7d66522c6 to your computer and use it in GitHub Desktop.
Save smilesrg/59f5fdd706a7d66522c6 to your computer and use it in GitHub Desktop.
PHP Factorial calculation usng BC Math extension
<?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