@reference: http://stackoverflow.com/questions/2556998/how-do-you-combine-two-foreach-loops-into-one
SPL MultipleIterator
@reference: http://docs.php.net/class.multipleiterator
// ArrayIterator is just an example, could be any Iterator. $a1 = new ArrayIterator(array(1, 2, 3, 4, 5, 6)); $a2 = new ArrayIterator(array(11, 12, 13, 14, 15, 16)); $it = new MultipleIterator; $it->attachIterator($a1); $it->attachIterator($a2); foreach($it as $e) { echo $e[0], ' | ', $e[1], "\n"; }
Prints
1 | 11
2 | 12
3 | 13
4 | 14
5 | 15
6 | 16
You must be logged in to post a comment.