+ 3
Php function
I have this code from one of the php questions in sololearn quiz: <?php function math($t){ if($t==0) return 0; return $t+ math($t-1); } echo math(6); ?> The output is 21. Can somebody explain me step by step the result. I tried but i quit. :) Thank you
5 Réponses
+ 3
i think it adds up all numbers 0 to n and outputs it
6+5+4+3+2+1=21
it uses recursion btw
+ 5
thank you
+ 3
yes..but this part i don t get: return $t + math($t-1)
+ 3
if you noticed the name of function is math and math is used again in itself so everytime it runs local variable t gets 1 lower
+ 2
razvan youre welcome ^-^