PHP rewinddir() Function

Definition

The rewinddir() function resets the directory handle created by opendir().

Syntax

PHP rewinddir() Function has the following syntax.

rewinddir(dir_handle);

Parameter

ParameterIs RequiredDescription
dir_handleOptional.Directory handle resource previously opened with opendir(). If this parameter is not specified, the last link opened by opendir() is assumed

Example

Open a directory, list its files, reset directory handle, list its files once again, then close:


<?php/*from   w  w  w  .  j  a v a2s. c o m*/
$dir = "/images/";
if (is_dir($dir)){
  if ($dh = opendir($dir)){
    // List files in images directory
    while (($file = readdir($dh)) !== false){
      echo "filename:" . $file . "\n";
    }
    rewinddir();
    // List once again files in images directory
    while (($file = readdir($dh)) !== false){
      echo "filename:" . $file . "\n";
    }
    closedir($dh);
  }
}
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions