Skip to content

Instantly share code, notes, and snippets.

@tanishiking
Last active August 29, 2015 14:22
Show Gist options
  • Save tanishiking/893b083ddadf9c234c4e to your computer and use it in GitHub Desktop.
Save tanishiking/893b083ddadf9c234c4e to your computer and use it in GitHub Desktop.
<?php
function mygenerator() {
yield 0;
yield 1;
yield 2;
yield 3;
}
$g = mygenerator();
var_dump($g->current()); # int(0)
$g->next();
var_dump($g->current()); # int(1)
$g->next();
var_dump($g->current()); # int(2)
$g->next();
var_dump($g->current()); # int(3)
foreach(mygenerator() as $i) {
var_dump($i);
} # 順にint(0), int(1), int(2), int(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment