1function getFactorial($int)
2{
3
4 $factorial = 1;
5 for ($i = $int; $i > 1; $i--)
6 {
7 $factorial *= $i;
8 }
9 echo "The factorial of " . $int . " is " . $factorial . '<br>';
10}
1// METHOD ONE
2const factorialNumber = num => {
3 let factorials = []
4 for(let i = 1; i <= num; i++) factorials.push(i)
5 return factorials.reduce((acc , curr) => acc * curr, 1)
6}
7
8// METHOD TWO
9const factorialNumber = num => {
10 let factorial = 1, i = 1
11 while(i <= num){ factorial *= i; i++ }
12 return factorial
13}
14// METHOD THREE
15function factorialNumber(num) {
16 if(num < 1) return 1
17 else return factorialNumber(num - 1) * num
18}