The PHP manual is confusing me as far as sorting arrays goes. Heres the array I have set up, and I'd like to sort it based on the 'ext'. I refer to these like $files[12]["ext"] = "jpg"
Code:
Array
(
[0] => Array
(
[name] => Empire.JPG
[path] => ./files/Empire.JPG
[size] => 191.01 kb
[ext] => JPG
[url] => localhost/wwwexplore/files/Empire.JPG
)
[1] => Array
(
[name] => Contact.gif
[path] => ./files/Contact.gif
[size] => 5.62 kb
[ext] => GIF
[url] => localhost/wwwexplore/files/Contact.gif
)
...
)
I tried doing array_multisort($files["ext"]) but it says arg#1 must be an array. I'm not really sure how to sort this.
--Edit:
Code:
function cmp($a, $b)
{
return strcmp($a["ext"], $b["ext"]);
}
printf(usort($files, "cmp"));
From the PHP manual, this has been bothering me for a long time but finally found it.
Last edited by RadGH; 09-16-2008 at 05:54 AM..
|