PHP遞歸返回值的問題

function test($a){
if($a>100){
return $a;
}
$a++;
test($a);
}

echo test(1);  ##這樣可能並不會返回101,無法輸出或得到相應的結果


改成

function test($a){
if($a>100){
return $a;
}
$a++;
return test($a);   ///加上return  則可以正常返回值了
}

echo test(1);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章