What is recursion in PHP?

Last updated 5 years, 1 month ago | 1649 views 75     5

Tags:- PHP

PHP | Recursion 

PHP also supports recursive function call like C/C++. In such a case, a function calls itself within the function.


Note: Recursion must be incorporated carefully since it can lead to an infinite loop if no condition is met that will terminate the function.


function display($num) {


    echo $num.”,”;    

    display($num+1);   //function call itself.




//Output will be 1, 2, 3, 4, 5