We already know how to get the factorial of a number in other languages. Let’s see how this is done in PHP using both recursive and non-recursive ways.
Input : 5 Output : 120 Input : 10 Output : 3628800
Method 1: Iterative way
In this method, we simply used the for loop to iterate over the sequence of numbers to get the factorial.
Method 2: Use of recursion
In this method we are calling the same method to get the sequence of the factorial.
- PHP | Check if a number is Perfect number
- PHP | Check if a number is armstrong number
- PHP | check if a number is Even or Odd
- PHP | Sum of digits of a number
- How to convert number to month name in PHP?
- AngularJS | number Filter
- How to format a number as currency using CSS ?
- What is the difference between parseInt() and Number()?
- How to convert a string into number in PHP?
- CSS | Number Data Type
- PHP | Check if a number is prime
- How to get the number of pages in a PDF document using PHP ?
- HTML | DOM Input Number Object
- PHP | Number of week days between two dates
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.