Sorting results of file list

PHP novice, my first post, thanks for any help!

I am comparing a portion of a file name ($file) to files in a directory and returning a sublist that matches the portion of the file name that was submitted. It works fine but the result are not in any particular order. I would simply like to sort the results but have spent a lot of time reading and still am clueless how to do it. Seems like it should be fairly easy. This is a typical time stamp file name: 2013-0214-1823.jpg

Here is my code so far:

[php]

// set directory name
$dir = “.”;

// set pattern
$pattern = $file;

// open directory and parse file list
if (is_dir($dir))
{
if ($dh = opendir($dir))
{
// iterate over file list
while (($filename = readdir($dh)) !== false)
{
// if filename matches search pattern, print it
if (fnmatch($pattern, $filename))
{
echo “<a href=”" . $filename . “”>" . $filename . “” . “\n” . “
”;
}
}
// close directory
closedir($dh);
}
}

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service