fibonacci.php:
<?php
$cache = array();
function fibonacci($nr) {
global $cache;
if (isset($cache[$nr])) {
return $cache[$nr];
}
switch ($nr) {
case 0:
die("Invalid Nr\n");
case 1:
return 1;
case 2:
return 1;
default:
$r = fibonacci($nr - 2) + fibonacci($nr - 1);
$cache[$nr] = $r;
return $r;
}
}
echo fibonacci($argv[1])."\n";
?>