php递归函数

特点:自己调用自己。

//求1+2+3的数字累加之和

$a=3;

$att = $this->sum($a);

public function sum($a){
$res+=$a;

if($a>1){
$res+=$this->sum(--$a);

}


return $res;

}
posted @ 2020-08-18 17:03  大熊童鞋  阅读(122)  评论(0编辑  收藏  举报