xxxxxxxxxx
<?php
function display($number) {
if($number<=5){
echo "$number <br/>";
display($number+1);
}
}
display(1);
?>
xxxxxxxxxx
<?php
function factorial($n)
{
if ($n < 0)
return -1; /*Wrong value*/
if ($n == 0)
return 1; /*Terminating condition*/
return ($n * factorial ($n -1));
}
echo factorial(5);
?>
xxxxxxxxxx
<?php
// PHP program to illustrate the
// Anonymous recursive function
$func = function ($limit = NULL) use (&$func) {
static $current = 10;
// if condition to check value of $current.
if ($current <= 0) {
//break the recursion
return FALSE;
}
// Print value of $current.
echo "$current\n";
$current--;
$func();
};
// Function call
$func();
?>