Page 1 of 1

order array by subarray element

Posted: Wed Aug 30, 2006 2:30 am
by pedrotuga
I have something like this:

Code: Select all

$array[1]["a"]=rand();
$array[1]["b"]=rand();
$array[1]["a"]=rand();
$array[2]["b"]=rand();
$array[3]["a"]=rand();
$array[3]["b"]=rand();
$array[4]["a"]=rand();
$array[4]["b"]=rand();
and i want to order the main array by, lets say, "a", without destroying the main "a" and "b" pairs.
I mean:

the subarrays should not be touched, only the top level array should be rearanged by a subarray element.


how should i do this?

Posted: Wed Aug 30, 2006 2:58 am
by volka
http://de2.php.net/usort might be what you're looking for.

Posted: Thu Aug 31, 2006 12:24 am
by pedrotuga
yep... it was exactly what i was looking for.

thanks