目录

PHP rewinddir() 函数

❮ PHP 目录参考

示例

打开一个目录,列出其文件,重置目录句柄,再次列出其文件,然后关闭:

<?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() 函数重置由以下命令创建的目录句柄打开目录()


语法

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 目录参考