Wednesday, 4 May 2011

Fibonacci series in PHP

<?php

$first = 0;
$second = 1;
$n = 20; // number of times you want to print the value
print $first.'<br>'; // print the first value
for($i=1;$i<$n;$i++)
{
  $final = $first + $second;
  $first = $second;
  $second = $final;
  print $final.'<br>';
}

?>

No comments:

Post a Comment