0
Help with Function Return example
I try to understan by myself but I just could not do it. I need help with the process of this example <?PHP function math($t) { if($t==0) return 0; return $t + math($t - 1); } echo math(6); ?> The result is 21 Why?
1 ответ
+ 2
In this example is used recursion => a function which calls itself. It's defined the base case ($t==0 ). The function will call itself until the base case is reached. So the result is 6+5+4+3+2+1 => 21.