How can PHP be used to display files and directories in a directory structure similar to Windows Explorer?

To display files and directories in a directory structure similar to Windows Explorer using PHP, we can use the `scandir()` function to get a list of files and directories in a specified directory. We can then iterate through the list and display them in a structured format using HTML.

<?php
$dir = 'path/to/directory';

$files = scandir($dir);

echo '<ul>';
foreach ($files as $file) {
    if ($file != '.' && $file != '..') {
        echo '<li>' . $file . '</li>';
        if (is_dir($dir . '/' . $file)) {
            $subfiles = scandir($dir . '/' . $file);
            echo '<ul>';
            foreach ($subfiles as $subfile) {
                if ($subfile != '.' && $subfile != '..') {
                    echo '<li>' . $subfile . '</li>';
                }
            }
            echo '</ul>';
        }
    }
}
echo '</ul>';
?>