Fibonacci Series Program in PHP Using For Loop

Fibonacci Series Program in PHP Using For Loop. Using this program we can print the recursion value in php program. The software below outputs the Fibonacci Series both with and without recursion. The result is displayed on the screen using the PHP echo statement.

The Fibonacci sequence, often known as Fibonacci numbers, is a set of integers in which each successive number is equal to the sum of the two preceding numbers. The Fibonacci Number Sequence is as follows: The Fibonacci Sequence is made up of the numbers 0, 1, 1, 2, and 3.

<?php

function fibonacci(\$x,\$y)
{
\$c = \$x + \$y;
return \$c;
}

\$a = 0;
\$b = 2;
echo "Fibonacci series";
echo "\$a, \$b";

for (\$i = 0; \$i < 26; \$i++)
{
echo ", ";
echo fibonacci(\$a,\$b);
\$z = fibonacci(\$a,\$b);
\$a = \$b;
\$b = \$z;

}
?>

Output:

Fibonacci series 0, 2, 2, 4, 6, 10, 16, 26, 42, 68, 110, 178, 288, 466, 754, 1220, 1974, 3194, 5168, 8362, 13530, 21892, 35422, 57314, 92736, 150050, 242786, 392836

Golden Number in Fibonacci Series Program in Php

The golden ratio, denoted by the Greek symbol phi, is approximately 1.618. The golden ratio is approximated by the ratios of sequential Fibonacci numbers (2/1, 3/2, 5/3, etc.). Indeed, the higher the Fibonacci numbers get, the closer they are to 1.618.

When the Fibonacci sequence is applied

Fibonacci numbers and lines are constructed using the ratios found in Fibonacci’s sequence. In financial markets, Fibonacci numbers are extensively employed. To get these ratios or percentages, divide particular values in the series by other numbers.