For an example:-
0 1 1 2 3 5 8 13 21
<?php
function printFabonacciSeries($number){
$a = 0; // first number of series
$b = 1; // second number of series
echo 'Fabonacci Series <br/>';
echo $a.' '.$b;
for($i=2;$i<$number;$i++){
$c = $a + $b; //print next number of series
echo ' '.$third;
$a = $b;
$b = $c;
}
}
printFabonacciSeries(9);
?>
Output :- 0 1 1 2 3 5 8 13 21
Alternate Way to Print Fabonacci Series :-
<?php
$number = 9;
$first = 0;
$second = 1;
echo "$first $second "; // 0 1
for($i=1;$i<= $number-2 ;$first=$second,$second=$third,$i++ )
{
echo $third = $first+$second; //print next number of series
echo " ";
}
?>
Using the above program you can find Fibonacci Series in PHP.
Note: Only a member of this blog may post a comment.