Last active
August 29, 2015 14:22
-
-
Save tanishiking/893b083ddadf9c234c4e 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 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