Home >Backend Development >PHP Tutorial >How to use php closedir function

How to use php closedir function

藏色散人
藏色散人Original
2019-02-20 11:56:112236browse

php The closedir() function is used to close the directory handle. Its syntax is closedir(dir_handle). The parameter dir_handle is optional and specifies the directory handle resource previously opened by opendir(). If this parameter is not specified, the last link opened by opendir() is used.

How to use php closedir function

#How to use the closedir function in php?

php closedir() function syntax

Function: Close the directory handle.

Syntax:

closedir(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.

Description: Close the directory handle.

php closedir() function usage example

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

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

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

Statement:
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