try using named key/value pairs in your array. your array right now is going to look like this:
$dates[0] = (timestamp)
$dates[1] = (timestamp)
$dates[2] = (timestamp)
$dates[3] = (timestamp)
and so on.
but if you named your keys as well, you'd have an associative array that matches filenames with timestamps. something like the following, maybe. (and please excuse my hybrid english/php; i'm just trying to get an example across.)
Code:
while(you've got some files left)
if(this is a jpg file)
{
// get this particular $filename
$dates[$filename] = filemtime($filename);
}
which will create an array something like this:
$dates["file1.jpg"] = (timestamp)
$dates["file2.jpg"] = (timestamp)
$dates["thatpictureofbrianwithhispantsoff.jpg"] = (timestamp)
and so on. now you can sort the array on the timestamp value (using sort($dates)) and just step through the array in sequence, to retrieve the filenames. of course, you'll have to retrieve the key rather than the value. here's one way to do it:
PHP:
foreach($dates as $key => $value)
{
// will step through the array in order
// and return two variables, $key and $value,
// correlating to filename and timestamp,
// for each pair.
echo '<img src="'.$key.'">'; // or whatever
}
or you could reverse the key/value when you create the $dates array:
PHP:
$dates[filemtime($filename)] = $filename
so you'd get an array in this format:
$dates["timestamp1"] = "file1.jpg";
then you could use ksort($dates) to sort the array on the key, and just retrieve the values as usual.
does that make sense?