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.
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);
}
?>Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.