Fibonacci numbers in PHP
Example for versions
PHP 5.2.4,
PHP 5.3.2
This example uses recursive definition of Fibonacci numbers.
<?php
function fibonacci($n)
{
if ($n < 3) {
return 1;
}
return fibonacci($n-1) + fibonacci($n-2);
}
for ($n = 1; $n <= 16; $n++) {
echo fibonacci($n) . ", ";
}
echo "...\n";
?>
Comments
]]>blog comments powered by Disqus
]]>