Generators in PHP implement the Iterator
interface, so you can merge / combine multiple Generator
s like you can combine multiple Iterator
s.
If you want to iterate over both generators one after the other (merge A + B), then you can make use of the AppendIterator
.
$aAndB = new AppendIterator();
$aAndB->append($generatorA);
$aAndB->append($generatorB);
foreach ($aAndB as $i) {
...
If you want to iterate over both generator at once, you can make use of MultipleIterator
.
$both = new MultipleIterator();
$both->attachIterator($generatorA);
$both->attachIterator($generatorB);
foreach ($both as list($valueA, $valueB)) {
...
Example for those two incl. examples and caveats are in this blog-post of mine as well:
Otherwise I don't understand what you've been asking for. If you could clarify, I should be able to give you more directions.