How can you use DirectoryIterator in PHP to read folder structures and create a menu?

To read folder structures and create a menu in PHP, you can use the DirectoryIterator class to iterate through the files and folders in a directory. You can then generate a menu by listing out the files and folders as links in an HTML list format.

<?php
$dir = new DirectoryIterator('/path/to/directory');

echo '<ul>';
foreach ($dir as $file) {
    if (!$file->isDot()) {
        echo '<li><a href="' . $file->getPathname() . '">' . $file->getFilename() . '</a></li>';
    }
}
echo '</ul>';
?>