Skip to content

Instantly share code, notes, and snippets.

@biroa
Created November 3, 2015 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save biroa/f8ec3349e3544700f1c1 to your computer and use it in GitHub Desktop.
Save biroa/f8ec3349e3544700f1c1 to your computer and use it in GitHub Desktop.
Fibonacci with loop solution
<?php
/**
* Created by PhpStorm.
* User: adam biro
* Date: 10/1/2015
* Time: 7:53 PM
*/
/**
* @param $n
*/
function fibonacci($n)
{
$first = 0;
$second = 1;
echo "Fibonacci series ";
echo $first . ' ' . $second . ' ';
for ( $i = 2; $i < $n; $i++ ) {
$third = $first + $second;
echo $third . ' ';
$first = $second;
$second = $third;
}
}
fibonacci(10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment