PHP rewinddir()関数
例
ディレクトリを開き、そのファイルを一覧表示し、ディレクトリハンドルをリセットし、そのファイルをもう一度一覧表示してから、閉じます。
<?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);
}
}
?>
結果:
filename: cat.gif
filename: dog.gif
filename: horse.gif
filename: cat.gif
filename: dog.gif
filename: horse.gif
定義と使用法
rewinddir()関数は、opendir()によって作成されたディレクトリハンドルをリセットします。
構文
rewinddir(dir)
パラメータ値
Parameter | Description |
---|---|
dir | Optional. Specifies the directory handle resource previously opened with opendir(). If this parameter is not specified, the last link opened by opendir() is assumed |
技術的な詳細
戻り値: | 成功した場合はNULL、失敗した場合はFALSE |
---|---|
PHPバージョン: | 4.0以降 |
❮PHPディレクトリリファレンス