Created
November 3, 2015 23:15
-
-
Save biroa/f8ec3349e3544700f1c1 to your computer and use it in GitHub Desktop.
Fibonacci with loop solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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