This function will return the factorial of $int (is the product of all positive integers less than or equal to n).
<?php
function factorial( $int )
{
// For as long $i is more or equal to 2
for ( $i = $int; $i >= 2; $i-- ):
// If $i is equal to $int
if ( $i == $int ):
$result = $int;
continue;
endif;
// Result
$result *= $i;
endfor;
// Return with number format
return number_format( $result );
}
// Factorial
echo factorial( 20 );
?>
This will output:
2,432,902,008,176,640,000
Mail this!
- Comments (0)
- PingBacks (0)
- TrackBacks (0)

» Latest comments