Created
August 31, 2019 17:36
-
-
Save unique1984/9a04da1c7b924c7b7979e4a1bf8991ec to your computer and use it in GitHub Desktop.
Fibonacci Generator PHP
This file contains hidden or 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 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