Recursion Function in PHP With Example

In this post, you will learn about the recursion function in PHP  With examples.



PHP also supports recursive function call like C, C++. The recursion function continues until some condition is met to stop it.

Recursive function in PHP with example

A function is recursive if it calls itself and reaches a stop condition.

Recursive function With examples

 



Output-

 

 

A recursive function is not good to use in PHP coding, sometimes if we never maintain the base value, then it may go for infinite, So it will be good if we can use the PHP loop.



Example of an infinite loop,  when missing the base value.

 

Maintain the base value in the above code.

 

 



 

Tags: