i’m making a basic directory listing script… so I use scandir, nothing fancy
$list = scandir($dir);
usort($list,"cmp");
I’m wanting to use usort to sort the list so that folders come first… and I really have absolutely no idea what i’m doing with usort
I have this:
function cmp($a,$b) {
if ($a == $b) {
return 0;
}
elseif(is_dir($a)) return -1;
else return 1;
}
once again I have no clue what i’m doing. But the above code works - it sorts all the folders first and then files, but in some obscure order. nothing’s alphabetic or anything (the original array was), it just seems completely random… is there anyway I could use usort and still have them alphabetical?..thanks