Program to Generate Fibonacci Series in PHP using For loop
ADVERTISEMENTS
Program to generate fibonacci series in PHP using for loop. In this article, you will learn how to make a program to generate fibonacci series in php using for loop.
Note: You should have knowledge of the Fibonacci series concepts to complete this before making this program.
Fibonacci Series Pattern
The Fibonacci series is: 1, 5, 6, 11, 17, 28, 45, 73
Source Code
<?php
// Program to Generate Fibonacci Series in PHP using For loop
$x = 8;
$i = 0;
$t1 = 1;
$t2 = 5;
$nt = 0;
// $x - To store the number of terms
// $t1 - To store the term 1
// $t2 - To store the term 2
// $nt - To store the next term
echo "Fibonacci Series:: ";
for ($i = 1; $i <= $x; $i++) {
echo $t1 . ", ";
$nt = $t1 + $t2;
$t1 = $t2;
$t2 = $nt;
}
echo "\n";
?>
Output
Fibonacci Series:: 1, 5, 6, 11, 17, 28, 45, 73,