What are some best practices for listing directories without including files in PHP?
When listing directories in PHP, it is common to inadvertently include files along with directories. To avoid this, you can use the `is_dir()` function to check if an item is a directory before including it in the listing. Additionally, you can use `scandir()` to retrieve the contents of a directory and filter out any files before displaying the directories.
$dir = "/path/to/directory";
$contents = scandir($dir);
foreach ($contents as $item) {
if (is_dir($dir . '/' . $item)) {
echo $item . "<br>";
}
}