Can you sort files by date using readdir()

Code is below. I want to sort these in DESC order according the file date. Is there way to do that?

$dir = "../mydir/";
$dh  = opendir($dir);
//	get file names
while (false !== ($filename = readdir($dh))) {
	if($filename !="." AND $filename !=".."){
	echo "<li>".substr($filename, 0, -4)."</li>";
	}
}

I could always add a database entry to the process but I am trying to keep it simple.

Thanks for any help.

$dir = "../mydir/";
chdir($dir);
array_multisort(array_map('filemtime', ($files = glob("*.*"))), SORT_DESC, $files);
foreach($files as $filename)
{
	echo "<li>".substr($filename, 0, -4)."</li>";
}

Brilliant. Many thanks!

If you’re using PHP5 it has dedicated flags to sort files in a directory using the [fphp]scandir[/fphp] function