How can PHP be used to output the names of folders within a directory?

To output the names of folders within a directory using PHP, you can use the `scandir()` function to scan the directory and then loop through the results to check if each item is a directory. If it is a directory, you can output its name.

$dir = "/path/to/directory";
$folders = array_diff(scandir($dir), array('..', '.'));

foreach($folders as $folder){
    if(is_dir($dir . '/' . $folder)){
        echo $folder . "<br>";
    }
}