the directories on my system appear to have always the right order
I changed first loop for testing only
but the rest works 100% on my sys:
<?php
function cmp($a,$b) {
if ($a == $b) return 0;
return ($a < $b) ? -1 : 1;
}
// random order of directories, but they really exist
$arrDirs = array("2002","2004","2003","3008","2000","2001");
// print order before sorting
print_r($arrDirs);
usort($arrDirs, "cmp");
$arrFiles = array();
for($x=0; $x<count($arrDirs); $x++)
{
$handle=opendir("photos/" . $arrDirs[$x] . "/");
// make every subdir an array - nessecary!!!
$arrFiles[$x] = array();
while($file=readdir($handle))
{
if($file != "." && $file != ".." && ereg("_s.jpg$",$file))
{
$arrFiles[$x][count($arrFiles[$x])] = $file;
}
}
closedir($handle);
sort($arrFiles[$x]);
}
// print final order of dirs
print_r($arrDirs);
?>