A function that call itself is known as *Recursive Function*. Recursive function keeps calling itself. We have to set a condition that will stop it, otherwise it will run infinitely. This condition is known as a base case. Basically, base case tells the recursive function when to stop.
One such example of recursive function is to find out factorial of a number n.
function fact($num) {
if ($num === 0) { // our base case which stop the recursive function
return 1;
}
else {
return $num * fact($num-1); // calling itself.
}
}
0 Comment(s)