# How To Write a Program For Fibonacci Series in PHP

Hello, everyone in this tutorial I will explain “**How To Write a Program For Fibonacci series in PHP** “. First two Fibonacci numbers are 0 and 1. After that, each number will be the sum of previous two numbers. Now we can see that third Fibonacci number is 1 ( sum of first two numbers 0 + 1), and fourth Fibonacci number will be the sum of third and second number ( 1 + 1 = 2 ) , and fifth Fibonacci number will be the sum of fourth and third number ( 2 + 1 = 3 ). The series will go to that infinity.

## Here is the PHP script for printing first 20 Fibonacci numbers:

1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?php /* Writing a Program for Fibonacci Series in PHP */ $no1 = 0; $no2 = 1; $sum = 1; echo $no1 . ', ' . $no2; for ($um = 1; $sum < 10; $sum++) { $sum = $no1 + $no2; echo ", " . $sum; $no1 = $no2; $no2 = $sum; } ?> |

### Output:

1 |
0, 1, 1, 2, 3, 5, 8, 13 |

In this example I have created a series using for loop, you can also use while loop to create the same series.