pencapchew Posted January 2, 2007 Share Posted January 2, 2007 i'm making a basic directory listing script... so I use scandir, nothing fancy[code]$list = scandir($dir);usort($list,"cmp");[/code]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 usortI have this:[code]function cmp($a,$b) { if ($a == $b) { return 0; } elseif(is_dir($a)) return -1; else return 1;}[/code]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 Link to comment https://forums.phpfreaks.com/topic/32535-sorting-a-scandir-array-with-folders-first-using-usort/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.