function sum($shu){ if ($shu>1) { return $shu + sum($shu - 1); # code... }else{ return 1; } } echo sum(5);
How do you analyze this code and finally get the result 15? I went to some PHP groups and asked someone who said:
5 (5-1 4-1 3-1 2-1 1 ) Calculated in this way, the $shu retains the original number, and I don’t think the people in the tutorial said this. The $shu will also change instead of always being 5Which analysis is the best? That's right. I'm a beginner who just started, so I was confused. I didn't understand the analysis in the tutorial, but I could understand the analysis asked in the group.