Combines multiple iterators into a single iterator, returning arrays of grouped values.
Description
This iterator synchronously iterates over multiple traversable sources, yielding an array where each element corresponds to the current value of each source. The iteration stops when the shortest iterator is exhausted.
Usage Example:
Description
Zipping two iterators
use FastForward\Iterator\ZipIteratorIterator;
use ArrayIterator;
$dataSetOne = new ArrayIterator([1, 2, 3]);
$dataSetTwo = new ArrayIterator(['A', 'B', 'C']);
$zippedIterator = new ZipIteratorIterator($dataSetOne, $dataSetTwo);
foreach ($zippedIterator as $pair) {
print_r($pair);
}
// Outputs:
// [1, 'A']
// [2, 'B']
// [3, 'C']
Note: The iterator stops when the shortest iterable is exhausted.
Properties
Methods
Initializes the ZipIteratorIterator.
Counts the number of elements available in the iterator.
Retrieves the current set of values from each iterator.
Retrieves the current key (index) of the iteration.
Moves to the next set of values in each iterator.
Resets the iterator to the beginning.
Checks if all iterators still have valid elements.
Initializes the ZipIteratorIterator.
public
__construct(
iterable<string|int, mixed>
...$iterators) : mixed
Parameters
$iterators
:
iterable<string|int, mixed>
Description
The iterators to be combined.
Description
if fewer than two iterators are provided
Counts the number of elements available in the iterator.
public
count() : int
Description
This method MUST count the elements by iterating over a clone of the current iterator instance so that the active iterator state of the original object is not modified during the counting process. Concrete implementations SHOULD therefore remain safely cloneable whenever this behavior is expected to be used.
Return values
Description
the total number of elements exposed by the iterator
Retrieves the current set of values from each iterator.
public
current() : array<int, mixed>
Return values
Description
the array of current values from each iterator
Retrieves the current key (index) of the iteration.
public
key() : int
Return values
Description
the current index
Moves to the next set of values in each iterator.
public
next() : void
Resets the iterator to the beginning.
public
rewind() : void
Checks if all iterators still have valid elements.
public
valid() : bool
Description
The iteration stops when the shortest iterator is exhausted.
Return values
Description
true if valid elements exist, false otherwise