Jump to content

Best way to sort directory array by extension


RadGH

Recommended Posts

I have an array with a list of files given from a directory using this directoryToArray() function here. And example array would be:

 

$Files[0] = "./files/my_zip.zip"
$files[1] = "./files/image.bmp"
$Files[2] = "./files/your_zip.zip"

 

I'm need some help sorting this by the extension. If anyone has some other suggestions I'm totally open to them, what I'm trying to do is list any selected folder with Javascript in a table listing the name, extension, size, and date modified. Simple. But I'd like it to be more user friendly for larger folders.

 

I've tried a few things. Simply sorting worked alphabetically, but thats not good enough. Splitting the array into a 2d array with the second element being the extension, and then sorting the second array would have worked but I couldn't find a sufficient way to accomplish that.

 

Also, is there a more efficient way to find the extension than using:

		$ext = explode("/", $file);
	$ext = explode(".", $ext[count($ext) - 1]);
	$ext = $ext[count($ext) - 1];

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.