Backend Development 2 min read

PHP closedir() – Closing a Directory Handle

The article explains the PHP closedir() function, which closes a directory handle opened by opendir(), describes its parameter and lack of return value, and provides a complete example demonstrating how to open, read, and close a directory in PHP.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP closedir() – Closing a Directory Handle

The closedir() function in PHP closes the directory stream identified by the $dir_handle resource that was previously opened with opendir() . The function does not return any value.

Parameter: dir_handle – a resource representing the directory handle, typically the last handle opened by opendir() if none is explicitly specified.

Return value: None.

Example:

<?php
$dir = "/etc/php5/";
// Open a known directory, read directory into variable and then close
if (is_dir($dir)) {
    $dh = opendir($dir);
    $directory = readdir($dh);
    closedir($dh);
}
?>
backendphpfilesystemphp-functionsclosedirdirectory-handle
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.