php opendir sort
<p>Im currently outputting all text files held in a directory:</p>

<pre><code>$directory = "polls/";
$dir = opendir($directory);


while (($file = readdir($dir)) !== false) {
  $filename = $directory . $file;
  $type = filetype($filename);
  if ($type == 'file') {
  $contents = file_get_contents($filename);
  list($tag, $name, $description, $text1, $text2, $text3, $date) = explode('¬', $contents);

  echo '&lt;table width="500" border="1" cellpadding="4"&gt;';
  echo "&lt;tr&gt;&lt;td&gt;$tag&lt;/td&gt;&lt;/tr&gt;\n";
  echo "&lt;tr&gt;&lt;td&gt;$name&lt;/td&gt;&lt;/tr&gt;\n";
  echo "&lt;tr&gt;&lt;td&gt;$description&lt;/td&gt;&lt;/tr&gt;\n";
  echo "&lt;tr&gt;&lt;td&gt;$text1&lt;/td&gt;&lt;/tr&gt;\n";
  echo "&lt;tr&gt;&lt;td&gt;$text2&lt;/td&gt;&lt;/tr&gt;\n";
  echo "&lt;tr&gt;&lt;td&gt;$text3&lt;/td&gt;&lt;/tr&gt;\n";
  echo "&lt;tr&gt;&lt;td&gt;$date&lt;/td&gt;&lt;/tr&gt;\n";
  echo '&lt;/table&gt;';

  }
}
closedir($dir);
</code></pre>

<p>I would like to extend this so that the files are sorted before output, there unixtime format filenames so aphabetically should do it. Then I only want to output the first 5 after they have been sorted. That should give me the latest 5.</p>
