I can't quite work out the logic in my head but im pretty sure you could do it using getlastmod() and sort($array,SORT_NUMERIC)
Personally, I use a database for my photo gallery, with a date column so I can sort by date added...
You could use a multidimensional array, each file has a stored filename and date modified
e.g.
$thumbs[0][0] = 'filename.jpg'
$thumbs[0][1] = '324729874'
then use array_multisort() to sort by [i][1] then just display the images using foreach
second edit:
here's some code posted on PHP.net for sorting multidimensional arrays:
PHP Code:
<?php
function matrixSort(&$matrix,$sortKey) {
foreach ($matrix as $key => $subMatrix)
$tmpArray[$key] = $subMatrix[$sortKey];
arsort($tmpArray);
return array_merge($tmpArray,$matrix);
}
?>
Of course, I could be going about this totally the wrong way...