In this article, We’ll write a program to generate a factorial of any number in php.
first, we understand the meaning of factorial
in mathematics, the factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n.
For example:
5! = 5 * 4 * 3 * 2 * 1 = 120
Below an example:
$number = 5; $fact = 1; while($number > 0) { $fact = $fact * $number; $number--; } echo $fact; // Output 120
In above, we wrote a program to generate the factorial of 5 and the factorial of 5 came 120.
That’s it!. Please share your thoughts or suggestions in the comments below.