tibberous Posted December 20, 2007 Share Posted December 20, 2007 I needed to soft files by their extension. $dir = opendir($path); $files = array(); function sortByExt($x, $y){ return strcmp($x['ext'], $y['ext']); } while($file = readdir($dir)){ if($file == '.' || $file == '..') continue; $ext = explode('.', $file); $ext = array_pop($ext); $files[] = array('file'=>$file, 'ext'=>$ext); } usort($files, "sortByExt"); I was thinking there was a way to do it without usort, just like a 'sort by value' kind of thing. Link to comment https://forums.phpfreaks.com/topic/82594-did-i-do-this-weird/ Share on other sites More sharing options...
Jessica Posted December 20, 2007 Share Posted December 20, 2007 That's how I'd do it, that's what usort is for. Link to comment https://forums.phpfreaks.com/topic/82594-did-i-do-this-weird/#findComment-419913 Share on other sites More sharing options...
Ninjakreborn Posted December 20, 2007 Share Posted December 20, 2007 That's what it's used for. You did good. Link to comment https://forums.phpfreaks.com/topic/82594-did-i-do-this-weird/#findComment-419915 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.