Rewind the DirectoryIterator back to the start in PHP

Description

The following code shows how to rewind the DirectoryIterator back to the start.

Example


/*from w  w  w.  jav  a  2s  .c  om*/
<?php
$iterator = new DirectoryIterator(dirname(__FILE__));

$iterator->next();
echo $iterator->key(); //1

$iterator->rewind(); //rewinding to the beginning
echo $iterator->key(); //0
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    File »




Directory
DirectoryIterator
Drive
File
File Permission
File Read Save
FileSystemIterator
Path
Zip