Easy Tutorial
❮ Func Array Udiff Assoc Func Mysqli Debug ❯

PHP rewinddir() Function

PHP Directory Reference Manual

Example

Open a directory, list its files, reset the directory handle, list its files again, and then close it:

<?php
$dir = "/images/";

// Open directory and read contents
if (is_dir($dir)){
    if ($dh = opendir($dir)){
        // List files in the images directory
        while (($file = readdir($dh)) !== false){
            echo "filename:" . $file . "<br>";
        }
        rewinddir();
        // List files in the images directory again
        while (($file = readdir($dh)) !== false){
            echo "filename:" . $file . "<br>";
        }
        closedir($dh);
    }
}
?>

Result:

filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif

Definition and Usage

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


Syntax

Parameter Description
dir_handle Optional. Specifies the directory handle previously opened by opendir()

Technical Details

Return Value: -
PHP Version: 4.0+
--- ---
❮ Func Array Udiff Assoc Func Mysqli Debug ❯