Using a recursive function to sum an integer set : Function Recursion « Functions « PHP






Using a recursive function to sum an integer set

 
<?
function summation ($count) {
     if ($count != 0) :
          return $count + summation($count-1);
     endif;
}
$sum = summation(10);
print "Summation = $sum";
?>
  
  








Related examples in the same category

1.Define recursive function to delete directories
2.Function Recursion Demo
3.A recursive function is a function that calls itself from within its own code.
4.Recursive Function Example
5.Recursive Functions