Fibonacci Series in php

Fibonacci series is a sequence of number generated by adding the previous two terms.

Example-

1, 2, 3, 5, 8, 13, 21,….. and so on.

At a first glance you can check that, starting from 3rd term its an addition of previous two values.

You can also write a simple program in PHP for this series generation –

$a = 1;
$b = 2;
$term = 10;
$i = 0;

echo $a." ".$b." ";
for($i; $i < $term -2 ; $i++)
{
$c = $b +$a;
echo $c." ";
$a = $b;
$b = $c;
}

Output –

1 2 3 5 8 13 21 34 55 89

Posted in PHP