Having trouble sorting

Hello, I have created a dropdown which gathers all the folders (thats all i have in the directory) names and outputs them as correctly named links for my WP site, and this works fine.

The problem I am having is sorting the results in my dropdown in alphabetical order, it is seemingly random but static at the moment.

Here is the php I am using (within the dropdown).

<ul style="nav3" id="nav3">
  • Select Year

      <?php $path = "pdfs/notifications";

      if ($handle = opendir($path))
      {
      while (false !== ($file = readdir($handle))) {
      if (is_dir($path . ‘/’ .$file)) {
      if (substr($file, 0, 1) !== “.” )

      {

      echo “

    • <a href=“notifications-{$file}”>”,basename($file),"
    • \n";
      }
      }
      }
        closedir($handle);
    

    }
    ?>

  • I would really appreciate any help anybody can offer with this.
    Thanks in Advance
    Luke

    Sponsor our Newsletter | Privacy Policy | Terms of Service