重新排序从目录生成的列表

I have this code that will pull the information from a folder(flat directory) on the site and will generate a list of the files for downloading using php. It looks at the first two characters of the file names and based on this "prefix" will create a Month heading for each section. This makes it appear that it is not "flat".

It works great, but I need for it to place the newest files at the top instead of at the bottom. I can easily change the order of the headings by rearranging the array keys.

I would be grateful for suggestions on how to do this. Here is the code:

<?php
$prevgroupprefix = '';

if ($handle = opendir('bulletin')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $groupprefix = substr($file,0,2);
            $period = strrpos($file, ".");
            $filepath = "bulletin/" . $file;
            $file = substr($file,0,$period);
            if ($groupprefix <> $prevgroupprefix){
            $title = "$groupprefix Weekly Bulletins";
            $month = array(
                    "01" => "January",
                    "02" => "February",
                    "03" => "March",
                    "04" => "April",
                    "05" => "May",
                    "06" => "June",
                    "07" => "July",
                    "08" => "August",
                    "09" => "September",
                    "10" => "October",
                    "11" => "November",
                    "12" => "December"
                );

                Switch($groupprefix)
                {
                    Case "01":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[01]</div>";
                        break;

                    Case "02":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[02]</div>";
                        break;

                    Case "03":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[03]</div>";
                        break;

                    Case "04":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[04]</div>";
                        break;

                    Case "05":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[05]</div>";
                        break;

                    Case "06":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[06]</div>";
                        break;

                    Case "07":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[07]</div>";
                        break;

                    Case "08":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[08]</div>";
                        break;

                    Case "09":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[09]</div>";
                        break;

                    Case "10":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[10]</div>";
                        break;

                    Case "11":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[11]</div>";
                        break;

                    Case "12":
                        $title = "<div id='bulletinmonth'>$groupprefix - $month[12]</div>";
                        break;

                    Case ".D":
                        $title = "";
                        break;
                }
                echo "<tr><td higth='50%'>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
                echo "<tr><td>&nbsp;</td><td> $title </td><td>&nbsp;</td></tr>";
            }
            echo "<div id='bulletinbody'><ul><li><a href='$filepath'target='_blank'> $file </a></li></ul></div>";
            $prevgroupprefix = $groupprefix;
        }
    }
    closedir($handle);
}
?> 

Maybe you should use scandir (return array of all files) and then use array_reverse ?