Factorial program in PHP using recursive function
Exercise Description:
Write a PHP program to find factorial of a number using recursive function.
What is Recursive Function?
- A recursive function is a function that calls itself.
Factorial program in PHP using recursive function
<?php
function factorial($number) {
if ($number < 2) {
return 1;
} else {
return ($number * factorial($number-1));
}
}
echo factorial(4);
?>
Tutorials Class - Output Window
24
Learn more about the similar topics:
Tutorials |
---|
No Content Found. |
Exercises & Assignments |
---|
Factorial program in PHP using recursive function |
Interview Questions & Answers |
---|
No Content Found. |