Skip to content

UniqueIteratorIterator

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

Class UniqueIteratorIterator.

Filters duplicate values from an iterator, ensuring uniqueness.

This iterator allows traversing an iterable while maintaining a record of seen values, returning only the first occurrence of each unique value. Subsequent occurrences are skipped.

Usage Example:


Methods

__construct

Initializes the UniqueIteratorIterator.

public __construct(iterable $iterator, bool $strict = true, bool $caseSensitive = true): mixed

Parameters:

Parameter Type Description
$iterator iterable the iterator to filter for unique values
$strict bool whether to use strict comparison (default: true)
$caseSensitive bool whether to use case-sensitive comparison (default: true)

key

Retrieves the normalized sequential key for the current unique element.

public key(): int

Return Value:

the zero-based position of the current unique value


next

Advances to the next unique element.

public next(): void

rewind

Resets the iterator and clears the seen values.

public rewind(): void

Inherited methods

count

Counts the number of elements in the iterable.

public count(): int

If the inner iterator implements Countable, it uses that. Otherwise, it counts the elements by iterating through them.

Return Value:

the number of elements in the iterable


Clone this wiki locally