PHP 7.0.6 Released

Examples

Example #1 Factorial function using GMP

<?php
function fact($x
{
    
$return 1;
    for (
$i=2$i <= $x$i++) {
        
$return gmp_mul($return$i);
    }
    return 
$return;
}

echo 
gmp_strval(fact(1000)) . "\n";
?>

This will calculate factorial of 1000 (pretty big number) very fast.

User Contributed Notes

Juliano Barreto
7 months ago
I forgot to mention. You need (obviously) to remove the gmp function for a usual one. Like this:

function fact($num)
{
    $res = 1;
    for ($n = $num; $n >= 1; $n--)
        $res = $res*$n;
    return $res;
}
To Top