Skip to content

Instantly share code, notes, and snippets.

@Tocacar
Created November 8, 2018 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tocacar/4407c585bc71e56847f2aa336d4bf9db to your computer and use it in GitHub Desktop.
Save Tocacar/4407c585bc71e56847f2aa336d4bf9db to your computer and use it in GitHub Desktop.
function count_to_ten() {
yield 1;
yield 2;
yield from [3, 4];
yield from new ArrayIterator([5, 6]);
yield from seven_eight();
yield 9;
yield 10;
}
function seven_eight() {
yield 7;
yield from eight();
}
function eight() {
yield 8;
}
foreach (count_to_ten() as $num) {
echo "$num ";
}
// This yields 1 2 3 4 5 6 7 8 9 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment