function sum($n){ if($n > 1){ $tmp = sum($n -1) + $n; echo $n, ‘<br />‘; return $tmp; }else{ echo 1 , ‘<br />‘; return 1; } } echo sum(5); echo ‘<br />‘.‘=========================‘; function sum2($n){ if($n > 1){ echo $n, ‘<br />‘; return sum2($n -1) + $n; }else{ echo 1 , ‘<br />‘; return 1; } } echo sum2(5);
时间: 2024-10-27 12:48:27