php8.5
Home/ Manual/ spl / norewinditerator/ NoRewindIterator::rewind

NoRewindIterator::rewind

PHP function Edit on GitHub ✎

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

Prevents the rewind operation on the inner iterator

Description

NoRewindIterator::rewind(): void

Prevents the rewind operation on the inner iterator.

Parameters Parameters

Return Values

Void

Examples

NoRewindIterator::rewind() example

This example demonstrates that calling rewind on a NoRewindIterator object has no effect.

php
<?php
$fruits = array("lemon", "orange", "apple", "pear");

$noRewindIterator = new NoRewindIterator(new ArrayIterator($fruits));

echo $noRewindIterator->current() . "\n";
$noRewindIterator->next();
// now rewind the iterator (nothing should happen)
$noRewindIterator->rewind();
echo $noRewindIterator->current() . "\n";
?>

The above example will output:

output
lemon
orange

Source: reference/spl/norewinditerator/rewind.xml · from the official PHP manual (php/doc-en)