PHP rewinddir()函数与示例

柔光的暖阳◎ 2023-03-05 12:41 107阅读 0赞

PHP rewinddir()函数 (PHP rewinddir() function)

rewinddir() function is used to rewind/reset the directory handle which is created by the opendir() function.

rewinddir()函数用于后退/重置由opendir()函数创建的目录句柄。

Syntax:

句法:

  1. rewinddir(dir_handle);

Parameter(s):

参数:

  • dir_handle – it is an optional parameter which is used to specify the directory handle resource if we do not specify the directory handle resource – it assumes the last link opened with opendir() function.

    dir_handle –是一个可选参数,如果我们未指定目录句柄资源,则用于指定目录句柄资源–假定使用opendir()函数打开的最后一个链接。

Return value:

返回值:

It returns nothing.

它什么也不返回。

Example: PHP code to demonstrate example of rewinddir() function

示例:PHP代码演示rewinddir()函数的示例

  1. <?php
  2. $path = "/home";
  3. //checking whether $path is a directory or not
  4. //then, opening the directory and reading its files
  5. if (is_dir($path)) {
  6. if ($dh = opendir($path)) {
  7. while (($file = readdir($dh)) !== false) {
  8. echo "File:" . $file . "<br/>";
  9. }
  10. //rewinding/reset the directory handle
  11. rewinddir();
  12. //reading the files again
  13. while (($file = readdir($dh)) !== false) {
  14. echo "File:" . $file . "<br/>";
  15. }
  16. //closing the directory
  17. closedir($dh);
  18. }
  19. }
  20. ?>

Output

输出量

  1. File:.
  2. File:..
  3. File:main.php
  4. File:.
  5. File:..
  6. File:main.php

Reference: PHP rewinddir() function

参考: PHP rewinddir()函数

翻译自: https://www.includehelp.com/php/rewinddir-function-with-example.aspx

发表评论

表情:
评论列表 (有 0 条评论,107人围观)

还没有评论,来说两句吧...

相关阅读