Last active
August 29, 2015 14:22
-
-
Save harunyasar/679a9147a0786841c7e6 to your computer and use it in GitHub Desktop.
Simple Fibonacci generator
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 | |
function fibonacci($item) { | |
$a = 0; | |
$b = 1; | |
for ($i = 0; $i < $item; $i++) { | |
yield $a; | |
$a = $b - $a; | |
$b = $a + $b; | |
} | |
} | |
# give me the first ten fibonacci numbers | |
$fibo = fibonacci(10); | |
foreach ($fibo as $value) { | |
echo "$value\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment