Skip to content

Instantly share code, notes, and snippets.

@jamesBan
Created February 5, 2021 13:13
Show Gist options
  • Select an option

  • Save jamesBan/5bf7e6543bc3e6c6183dba67034d25af to your computer and use it in GitHub Desktop.

Select an option

Save jamesBan/5bf7e6543bc3e6c6183dba67034d25af to your computer and use it in GitHub Desktop.
<?php
/**
* @return Generator
*/
function fib()
{
[$a, $b] = [0, 1];
while (true) {
yield $b;
[$a, $b] = [$b, $a + $b];
if ($b > 10000) {
return ;
}
}
}
foreach (fib() as $item) {
var_dump($item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment