Jump to content

Did I do this weird?


tibberous

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.