PHP rewinddir() function: Here, we will find out about the PHP rewinddir() function with its syntax, parameters, returns type, and example.
PHP rewinddir() function
rewinddir() function is utilized to rewind/reset the catalog handle which is made by the opendir() function.
Syntax:
rewinddir(dir_handle);
Parameter(s):
- dir_handle – it is a discretionary parameter which is utilized to determine the index handle asset on the off chance that we don’t indicate the registry
- handle asset – it accepts the last connection opened with opendir() function.
Return value:
- It returns nothing.
Example: PHP code to exhibit example of rewinddir() function
<?php
$path = "/home";
//checking whether $path is a directory or not
//then, opening the directory and reading its files
if (is_dir($path)) {
if ($dh = opendir($path)) {
while (($file = readdir($dh)) !== false) {
echo "File:" . $file . "<br/>";
}
//rewinding/reset the directory handle
rewinddir();
//reading the files again
while (($file = readdir($dh)) !== false) {
echo "File:" . $file . "<br/>";
}
//closing the directory
closedir($dh);
}
}
?>
Output
File:.
File:..
File:main.php
File:.
File:..
File:main.php
Reference: PHP rewinddir() function