Fibonacci Series Program in PHP
In this exercise, you will learn different ways to write Fibonacci series of programs using PHP.
The Fibonacci series are the sequence of numbers in which the next number is the sum of the previous two numbers. The Fibonacci series was well-known hundreds of years earlier. The "Fibonacci" name came from the nickname "Bonacci".
We can easily remember Fibonacci Sequence using the Fibonacci Day, which is November 23rd. As 23rd November has the digits "1, 1, 2, 3" which is part of the sequence.
0 + 1 = 1
1 + 1 = 2
1 + 2 = 3
2 + 3 = 5
0 ,1 , 1, 2, 3, 5, 8, 13, 21, 34....
Fibonacci Series Program in PHP using For Loop
Here, you will learn how to print Fibonacci series using a for loop in PHP. In this below code, $f1 contains first number, i.e., 0 and $f2 contains second number, i.e., 1 and $n contains total Fibonacci series number count.
Output of the above code
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040
1346269
Fibonacci Series Program in PHP using while loop
In the given program, we have used the while loop to print the Fibonacci series upto 15 in PHP.
Output of the above code:
need an explanation for this answer? contact us directly to get an explanation for this answerFibonacci series upto 15 : 0, 2, 2, 4, 6, 10, 16, 26, 42, 68, 110, 178, 288, 466, 754, 1220, 1974, 3194