title: How to sort files by date in PHP
body: <p>I currently have a script which allows me to output the list of files inside the same directory.</p>
  <p>The output shows the names, and then I used <code>filemtime()</code> function to show the date when the file was modified.</p>
  <p>How will I sort the output to show the latest modified file?</p>
  <p>This is what I have for now:</p>
  <pre><code>if ($handle = opendir('.')) {
      while (false !== ($file = readdir($handle))) {
          if ($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot;) {
              $lastModified = date('F d Y, H:i:s', filemtime($file));
              if(strlen($file)-strpos($file, &quot;.swf&quot;) == 4) {
                  echo &quot;$file - $lastModified&quot;;
              }
          }
      }
      closedir($handle);
  }
  </code></pre>