English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP rewinddir() Function Usage and Example

PHP Directory Reference Manual

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

Syntax

void rewinddir ( resource $dir_handle );

 Resets the directory stream specified by dir_handle to the beginning of the directory.

Parameter

Serial NumberParameters and Description
1

dir_handle(Required)

The directory handle resource opened by opendir(). If this parameter is not specified, the last opened link by opendir() is used.

Return value

Returns the filename on success, FALSE on failure.

Online Example

The following is the usage of this function: open a directory, list the files inside, and reset the directory handle, then list the files again, and finally close it:

<?php
   $dir = opendir("/var/www/images");
   
   while (($file = rewinddir($dir)) !== false) {
      echo "filename: " . $file . "<br" />";
   }
   
   rewinddir($dir);
   while (($file = rewinddir($dir)) !== false) {
      echo "filename: " . $file . "<br" />";
   }
   closedir($dir);
?>

Output result:

filename: .
filename: ..
filename: logo.gif
filename: mohd.gif
filename: .
filename: ..
filename: logo.gif
filename: mohd.gif