In mathematics, the factorial function (symbol: !) says to multiply all whole numbers from our chosen number down to 1.
Example : Factorial of 5 is –
5! = 5 x 4 x 3 x 2 x 1 = 120
Let’s achieve this with PHP –
<?php
$fact =1;
$n = 5; // user input
for($i=1; $i<=$n; $i++)
{
$fact = $fact * $i;
}
echo $fact;
// Output
// 120