rewinddir

(PHP 4, PHP 5, PHP 7)

rewinddir디렉토리 핸들을 되감습니다

설명

void rewinddir ([ resource $dir_handle ] )

dir_handle에 지정한 디렉토리 핸들을 디렉토리의 처음 위치로 되돌립니다.

인수

dir_handle

opendir()로 열린 디렉토리 핸들 resource. 디렉토리 핸들이 지정되지 않으면, opendir()로 열린 마지막 연결을 할당합니다.

add a note add a note

User Contributed Notes 2 notes

up
7
osamahussain897 at gmail dot com
6 years ago
/* Source Code */

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

// Open a directory, and read its contents
if (is_dir($dir)){
  if (
$dh = opendir($dir)){
   
// List files in images directory
   
while (($file = readdir($dh)) !== false){
      echo
"filename:" . $file . "<br>";
    }
   
rewinddir();
   
// List once again files in images directory
   
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
up
4
ASchmidt at Anamera dot net
6 years ago
It is crucial to note that rewinddir() does not simply start over at the beginning of the SAME directory list. Instead, this function first re-reads the directory - thus any file that were deleted (or inserted) since the original opendir() will be reflected after "rewinding".

In that respect, rewinddir() is equivalent to a closedir(), opendir() sequence, but without obtaining a new handle.
To Top