+ 1

Could you explain -> function returns itself in php

function func($x) { İf ($x == 0) { return 0; } else { return $x + func($x - 1); } } echo func(6); //output : 21

28th May 2020, 9:10 PM
Safaa Alnabhan
Safaa Alnabhan - avatar
1 Antwort
+ 6
It is recursion. It occurs when function can call itself. We can present this case such way: 6+5+4+3+2+1+0 = 21
28th May 2020, 9:25 PM
Konstantin Rybakov
Konstantin Rybakov - avatar