static $fabn = [];
if($n < 2){
$fabn[$n] = 1;
}else{
if(empty($fabn[$n])){
$fabn[$n] = fabnacci($n - 1, 0) + fabnacci($n - 2, 0);
}
}
if($all == 1){
return $fabn;
}else{
return $fabn[$n];
}
}
var_dump(implode(" ", fabnacci(10)));
var_dump(implode(" ", fabnacci(10)));
?>
返回显示
string(26) "1 1 2 3 5 8 13 21 34 55 89" string(26) "1 1 2 3 5 8 13 21 34 55 89"
原文:http://blog.51cto.com/hjun169/2084404