update page now
Longhorn PHP 2026 - Call For Papers

Voting

: max(one, one)?
(Example: nine)

The Note You're Voting On

Marcel G
15 years ago
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;
}
?>

<< Back to user notes page

To Top