Factorial Calculator
This program computes the exact factorial value for any given argument from 0 to 9999.  Because factorials can become extremely large very quickly, this program is limited to 9999 as the maximum argument value and it could take up to several seconds to compute very large factorial values. 

N factorial  N!  =  Π k  =  1 × 2 × 3 × ··· × N
  k = 1 

N (0  to  9999) =    

The EXACT value of 0 factorial is shown below and consists of 1 digit.
Processing time was 0.000012 sec.

Jay Tanner - 2017

The following PHP function is used as the foundation for the above program.  It computes the full, arbitrary-precision value of the factorial of any given non-negative integer argument.

A factorial is also a permutation (a specific linear sequence) in which case, the order of the items matters.  The factorial of N tells us the total count of the unique ways that N people could be lined up from left to right for a group photograph or how may distinct r-digit numerical values can be formed using N base 10 digits.

This function should be used with caution, since it can result in extremely large factorial values.  For example, even though the function could handle arguments greater than 9999, the factorial of 9999 equates to a 35656-digit number.  It may take up to several seconds to compute extremely large factorial values with the possibility of a time-out if too extreme.
   This function computes the arbitrary-precision factorial
   of a positive integer argument.

   Author   : Jay Tanner 2014
   Language : PHP v5.4.7
   License  : This source code is released under the provisions of the
              GNU Affero General Public License (AGPL), version 3.

   Input argument must be a positive integer.  Any decimal
   value will be truncated to an integer value without
   rounding, but negative values are invalid and will
   return FALSE.

   FALSE is returned on error if N is non-numeric or N < 0

   function bcN_Factorial ($PosInt="0")
   $N = trim($PosInt);

   if (!is_numeric($N) or $N < 0) {return FALSE;}

   $P = 1;

   for ($k=1;   $k <= $N;   $k++)
        $P = bcmul($P, $k);

   return $P;
So, if the factorial of non-negative integer N simply equates to the product all of the integers from 1 up to N multiplied together, then why does the factorial of 0 equate to 1?

The reason it equates to 1 is essentially due to a definition based on physical logic.

Physically, the value of the factorial represents a count of the number of distinct ways that N distinct entities can be arranged in a row.  There is only 1 physical way that 0 (zero) entities can be arranged in a row.  Even though it equates to an empty set, and essentially a moot point, it still counts as one.  Hence, by definition, zero factorial (0!) equates to 1.

Jay Tanner - 2017