title: How can I list all files in a directory sorted alphabetically using PHP?
body: <p>I'm using the following PHP code to list all files and folders under the current directory:</p>
  
  <pre><code>&lt;?php
      $dirname = ".";
      $dir = opendir($dirname);
  
      while(false != ($file = readdir($dir)))
          {
            if(($file != ".") and ($file != "..") and ($file != "index.php"))
               {
                echo("&lt;a href='$file'&gt;$file&lt;/a&gt; &lt;br /&gt;");
          }
      }
  ?&gt;
  </code></pre>
  
  <p>The problem is list is not ordered alphabetically (perhaps it's sorted by creation date? I'm not sure).</p>
  
  <p>How can I make sure it's <strong>sorted alphabetically</strong>?</p>