Home >Backend Development >PHP Tutorial >How to use php rewinddir function
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.
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)
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>"; } } ?>
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!