How to use php rewinddir function

藏色散人
Release: 2023-04-05 10:50:02
Original
2750 people have browsed it

The rewinddir function is a built-in function in PHP, used to roll back a directory handle. Its syntax is "rewinddir(dir_handle)", and the parameter "dir_handle" represents the directory handle resource previously opened by opendir.

How to use php rewinddir function

The rewinddir() function is a built-in function in PHP that is used to roll back directory handles. This function opens a directory and lists its files, resets the directory handle, lists its files again, and finally closes the directory handle. Send the directory handle as a parameter to the rewinddir function, returning Null on success and False on failure.

php How to use the rewinddir() function?

Function: Reset the directory handle created by opendir().

Syntax:

rewinddir(dir_handle)
Copy after login

Parameters:

dir_handle: Optional. Specifies a directory handle resource previously opened by opendir(). If this parameter is not specified, the last link opened by opendir() is used.

Return value: Null is returned on success and False on failure.

php rewinddir() function example

<?php
$dir = "/phpstudy/WWW/20180414/";
// 打开目录,然后读取其内容
if ($dh = opendir($dir)){
        while (($file = readdir($dh)) !== false)
        {
            echo "filename:" . $file . "<br>";
        }
        //重置目录句柄
        rewinddir();
        while (($file = readdir($dh)) !== false)
        {
            echo "filename:" . $file . "<br>";
        }
}
?>
Copy after login

This article is an introduction to the PHP rewinddir function. I hope it will be helpful to friends in need!

The above is the detailed content of How to use php rewinddir function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template