Recursive Function in PHP Example

Recursive Function in PHP Example. A simple php program recursion function to print the number. In this program we can print the number using recursion function. Functions are “self-contained” code modules that perform a single purpose. Data is often “taken in,” processed, and a result is “returned” by functions. Once you’ve written a function, you can use it over and over again. It’s possible to “call” functions from within other functions.

function display($num)
echo "$num <br/>";








Recursion Function in Php

A recursive function is one that invokes its own function. However, in PHP, you must be careful not to use more than a particular amount of recursive function calls, after the intended result has been obtained, there must be a method  to stop the recursion. PHP, like most other programming languages with functions, allows you to build recursive functions.

If Else Statement in Php

The if-else phrase is run regardless of whether the condition is true or false. The if-else statement differs from the if statement in a few ways. If the provided condition is true, one block of code is executed; if the condition is false, another block of code is executed. The if/else if statement can be used to generate a chain of if statements. The if statements are evaluated in order until one of the if expressions is true or the if/else if chain is complete. No code blocks are run if there is no true expression at the end of the if/else if chain.