Skip to content

Instantly share code, notes, and snippets.

@unique1984
Created August 31, 2019 17:36
Show Gist options
  • Select an option

  • Save unique1984/9a04da1c7b924c7b7979e4a1bf8991ec to your computer and use it in GitHub Desktop.

Select an option

Save unique1984/9a04da1c7b924c7b7979e4a1bf8991ec to your computer and use it in GitHub Desktop.
Fibonacci Generator PHP
<?php
function FibonacciGenerator()
{
$i = 0;
$j = 1;
for(;;) {
yield $j;
list($i, $j) = array($j, $i + $j);
}
}
foreach (FibonacciGenerator() as $item) {
echo $item . "\n";
if ($item >= 7540113804746346429) {
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment