Last active
August 29, 2015 14:22
-
-
Save tanishiking/90bbb588f143b8435d36 to your computer and use it in GitHub Desktop.
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 fib_gen() { | |
list($a, $b) = [0, 1]; | |
while(true) { | |
yield $a; | |
list($a, $b) = [$b, $a+$b]; | |
} | |
} | |
$fib = fib_gen(); | |
var_dump($fib->current()); # int(0) | |
$fib->next(); | |
var_dump($fib->current()); # int(1) | |
$fib->next(); | |
var_dump($fib->current()); # int(1) | |
$fib->next(); | |
var_dump($fib->current()); # int(2) | |
$fib->next(); | |
var_dump($fib->current()); # int(3) | |
$fib->next(); | |
var_dump($fib->current()); # int(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment