Skip to content

Instantly share code, notes, and snippets.

@harunyasar
Last active August 29, 2015 14:22
Show Gist options
  • Save harunyasar/679a9147a0786841c7e6 to your computer and use it in GitHub Desktop.
Save harunyasar/679a9147a0786841c7e6 to your computer and use it in GitHub Desktop.
Simple Fibonacci generator
<?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