Skip to content

Instantly share code, notes, and snippets.

@tanishiking
Last active August 29, 2015 14:22
Show Gist options
  • Save tanishiking/90bbb588f143b8435d36 to your computer and use it in GitHub Desktop.
Save tanishiking/90bbb588f143b8435d36 to your computer and use it in GitHub Desktop.
<?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