Write a program to find the factorial in php of a number.
Factorial of a number is the product of numbers from 1 to ‘n’.
Eg:- 5! = 1*2*3*4*5 = 120
PHP :-
<?php
$n = 10;
$product = 1;
for($i=1; $i<=$n; $i++)
{
$product = $product*$i;
}
echo 'The factorial of '.$n.' is '.$product;
?>
- Declare the number to $n
- Set $product as 1
- In a for loop, loop through 1 to $n
- Inside the for loop, multiply $i with $product
- Print the result after closing loop
For more information visit gmp_fact.
For more php related queries visit PHP