You can use array_product to calculate the factorial of n:
<?php
function factorial( $n )
{
if( $n < 1 ) $n = 1;
return array_product( range( 1, $n ));
}
?>
If you need the factorial without having array_product available, here is one:
<?php
function factorial( $n )
{
if( $n < 1 ) $n = 1;
for( $p++; $n; ) $p *= $n--;
return $p;
}
?>