<?php
function Fib($n) {
if ($n == 0 || $n == 1) {
return 1;
} else {
return Fib($n - 2) + Fib($n - 1);
}
}
?>
<?php
$FV = array(0 => 1,
1 => 1);
function Fib($n) {
global $FV;
if (!is_int($n) || $n < 0) {
return 0;
}
if(!isset($FV[$n])) {
$FV[$n] = Fib($n - 2) + Fib($n - 1);
}
return $FV[$n];
}
?>
<?php class Fibonacci { static $values = array(0 => 1, 1 => 1); static function num($n) { if (!is_int($n) || $n < 0) { return 0; } if (!isset(self::$values[$n])) { self::$values[$n] = self::num($n -2) + self::num($n - 1); } return self::$values[$n]; } } ?>