php8.5
Home/ Manual/ spl / filesystemiterator/ FilesystemIterator::rewind

FilesystemIterator::rewind

PHP function Edit on GitHub ✎

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

Rewinds back to the beginning

Description

FilesystemIterator::rewind(): void

Rewinds the directory back to the start.

Parameters Parameters

Return Values

Void

Examples

FilesystemIterator::rewind example

php
<?php
$iterator = new FilesystemIterator(dirname(__FILE__), FilesystemIterator::KEY_AS_FILENAME);

echo $iterator->key() . "\n";

$iterator->next();
echo $iterator->key() . "\n";

$iterator->rewind();
echo $iterator->key() . "\n";
?>

The above example will output something similar to:

output
apple.jpg
banana.jpg
apple.jpg

See Also

  • DirectoryIterator::rewind

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