Could someone explain why the result is 21 for this I don't get it. Thank you. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Could someone explain why the result is 21 for this I don't get it. Thank you.

function math($t){ if ($t==0) return 0; return $t+math($t-1); } echo math(6);

19th Sep 2019, 10:08 PM
Vitalie Melnic
Vitalie Melnic - avatar
1 Answer
0
Makes sense I was thinking of it like an if statement that would break after one iteration thanks a lot
19th Sep 2019, 10:14 PM
Vitalie Melnic
Vitalie Melnic - avatar