Created
November 30, 2015 14:16
-
-
Save ThijsFeryn/e4b706d415f3dd8dab48 to your computer and use it in GitHub Desktop.
PHP 7 generator delegation
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 | |
/** | |
* Generator delegation | |
*/ | |
function gen() | |
{ | |
yield 1; | |
yield 2; | |
yield from gen2(); | |
} | |
function gen2() | |
{ | |
yield 3; | |
yield 4; | |
} | |
foreach (gen() as $val) | |
{ | |
echo $val, PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment