Skip to content

ZipIteratorIterator

github-actions edited this page Mar 31, 2026 · 3 revisions

Combines multiple iterators into a single iterator, returning arrays of grouped values.

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:


Methods

__construct

Initializes the ZipIteratorIterator.

public __construct(iterable $iterators): mixed

Parameters:

Parameter Type Description
$iterators iterable The iterators to be combined.

Throws:

if fewer than two iterators are provided


current

Retrieves the current set of values from each iterator.

public current(): array<int,mixed>

Return Value:

the array of current values from each iterator


key

Retrieves the current key (index) of the iteration.

public key(): int

Return Value:

the current index


next

Moves to the next set of values in each iterator.

public next(): void

valid

Checks if all iterators still have valid elements.

public valid(): bool

The iteration stops when the shortest iterator is exhausted.

Return Value:

true if valid elements exist, false otherwise


rewind

Resets the iterator to the beginning.

public rewind(): void

Inherited methods

count

Counts the number of elements available in the iterator.

public count(): int

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 Value:

the total number of elements exposed by the iterator


Clone this wiki locally