# fibonacci series in PHP

chris (2006-04-10 12:31:12)
5866 views
3 replies
This Fibonacci implementation is easy to convert into C or java or any language really. I've done it in PHP because it's quick and easy to read and understand. The secret to this is remembering to declare two inital values rather than just one so that you start of with a pair to sum. This is easily converted to java or C or whatever language you want to use.
```<?php \$first = 0; \$second = 1; \$n = 27; \$inc = 1; do{ \$inc++; \$final = \$first + \$second; \$first = \$second; \$second = \$final; } while (\$inc < \$n) ; print "nn\$finalnn"; ?> ```
Sjan Evardsson
2009-05-21 19:36:11

This Fibonacci implementation is easy to convert into C or java or any language really. I've done it in PHP because it's quick and easy to read and understand. The secret to this is remembering to declare two inital values rather than just one so that you start of with a pair to sum. This is easily converted to java or C or whatever language you want to use.

In Python:
```first = 0 second = 1 n = 27 # we want to print the entire series, which start with 1, 1, 2, etc, neh? print second for i in range(n): next = first + second print next first = second second = next ```
Sjan
2009-05-21 19:39:52

## In Python

This Fibonacci implementation is easy to convert into C or java or any language really. I've done it in PHP because it's quick and easy to read and understand. The secret to this is remembering to declare two inital values rather than just one so that you start of with a pair to sum. This is easily converted to java or C or whatever language you want to use.

```first = 0 second = 1 n = 27 # to be correct we will print the entire series which starts off 1, 1, 2 ... print second for i in range(n): next = first + second print next first = second second = next ```
```first = 0 second = 1 n = 27 # to be correct we will print the entire series which starts off 1, 1, 2 ... print second for i in range(n): next = first + second print next first = second second = next ```