PHP rewinddir() Function
In this chapter you will learn:
- Definition for PHP rewinddir() Function
- Syntax for PHP rewinddir() Function
- Parameter for PHP rewinddir() Function
- Example - resets the directory handle created by opendir()
Definition
The rewinddir() function resets the directory handle created by opendir().
Syntax
PHP rewinddir() Function has the following syntax.
rewinddir(dir_handle);
Parameter
Parameter | Is Required | Description |
---|---|---|
dir_handle | Optional. | 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 j a v a 2 s. c om*/
$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);
}
}
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP rmdir() Function
- Syntax for PHP rmdir() Function
- Parameter for PHP rmdir() Function
- Return for PHP rmdir() Function
- Example - Delete an empty folder
Home » PHP Tutorial » PHP File Functions