The code below shows an example of a recursive function in PHP. The function starts with the number 1, and continues to run in a loop. Every time the function runs it increases the number by 1. The function stops looping after the number becomes greater than 8.
The Code
1 2 3 4 5 6 7 8 9 10 11 |
<?php function getHigher($number) { if($number > 8){ return $number; } else { return getHigher($number+1); } } echo getHigher(1); ?> |