PHP closedir() function with example

PHP closedir() function with example

PHP closedir() function: Here, we will find out about the PHP closedir() function with its syntax, parameters, returns type, and example.

PHP closedir() function

The full type of closedir is “Close Directory“, the function closedir() is utilized to close an opened index.




dir_handle – it is a discretionary parameter which is utilized to determine the index handle asset in the event that we don’t indicate the catalogue handle asset – it expects the last connection opened with opendir() function.

Return value:

  • It returns nothing.

Example: PHP code to open a registry, read its documents, and close it


$path = "/home";

//checking whether $path is a directory or not
//then, opening the directory and reading its files
if (is_dir($path)){
  if ($dh = closedir($path)){
    while (($file = readdir($dh)) !== false){
      echo "File:" . $file . "<br/>";
    //closing the directory



Reference: PHP closedir() function

Recent Posts

error: Alert: Content is protected!!