php8.5
Home/ Manual/ predefined / iterator/ Iterator::rewind

Iterator::rewind

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Rewind the Iterator to the first element

Description

Iterator::rewind(): void

Rewinds back to the first element of the Iterator.

Note

This is the first method called when starting a Foreach loop. It will not be executed after Foreach loops.

As Foreach always calls this method before starting iteration, manually advancing the iterator position (for example via SplFileObject::seek) will be reset.

To iterate without rewinding the iterator, wrap it in a NoRewindIterator.

Parameters Parameters

Return Values

Any returned value is ignored.

Source: language/predefined/iterator/rewind.xml · from the official PHP manual (php/doc-en)