How can the PHP script be modified to implement the sorting of folders by folder name in a chronological order?

To implement the sorting of folders by folder name in a chronological order, we can modify the PHP script to use the `scandir` function to scan the directory, sort the folders by name using `natsort`, and then iterate through the sorted array to display the folders in chronological order.

<?php
$dir = "./path/to/directory/";

$folders = array_diff(scandir($dir), array('..', '.'));

natsort($folders);

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