Fibonacci Series in PHP using for loop

Last updated:6th Jul 2022

The Fibonacci series starts with 0, and 1. a next number of the Fibonacci series is generated by adding the previous two numbers.

program for fibonacci series

<?php
$a=0;
$b=1;
echo "fibonacci series for 10 element are:</br>";
echo $a.'  '.$b;
for($num=0;$num<8;$num++)
{
    $next=$a+$b;
    echo '  '.$next;
    $a=$b;
    $b=$next;
}

output

fibonacci series for 10 element are:
0  1  1  2  3  5  8  13  21  34

Related Program