How to calculate factorial of a number in PHP. In this tutorial, I am going to discuss factorial program in PHP using recursion as well as iterative approach.
Before solving this problem let’s understand what is factorial?
What is Factorial?
Factorial of a non-negative integer n (n!), is the product of all positive integers less than or equal to n.
For example –
5! = 5 * 4 * 3 * 2 * 1 = 120
4! = 4 * 3 * 2 * 1 = 24