Back-End Development PHP basics

PHP Recursive functions

PHP Recursive functions are the functions which call themselves.

PHP Recursive functions are considered useful, as they break complex problems into simple cases, and solve a problem by reiterating those simple cases.

Most basic PHP Recursive functions

Let us begin with calculating factorial of a number using recursion:

The statement echo(4); calls the function fact. the value 4 gets assigned to $x. The program functions as :

Output: 24

Another example: