The Fibonacci sequence is named after Italian mathematician Fibonacci. His 1202 book Liber Abaci introduced the sequence to Western European mathematics, although the sequence had been described earlier in Indian mathematics.

The Fibonacci numbers or sequence is: 0,1,1,2,3,5,8,13,21,34,55,89,144…

Each number is the sum of the previous two numbers. In mathematical terms:

  • Fn=Fn−1+Fn−2 where F0=0,F1=1

Fibonacci numbers can be computed in several different ways. The following solution calculates each fibonacci number in sequence:

<?php
/**
* Created by PhpStorm.
* User: adam biro
* Date: 10/1/2015
* Time: 7:53 PM
*/
/**
* @param $n
*/
function fibonacci($n)
{
$first = 0;
$second = 1;
echo "Fibonacci series ";
echo $first . ' ' . $second . ' ';
for ( $i = 2; $i < $n; $i++ ) {
$third = $first + $second;
echo $third . ' ';
$first = $second;
$second = $third;
}
}
fibonacci(10);
view raw Fibonacci.php hosted with ❤ by GitHub
algorithms fibonacci sequence php coding
comments powered by Disqus