order array by subarray element

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

order array by subarray element

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://de2.php.net/usort might be what you're looking for.
User avatar
pedrotuga
Forum Contributor
Posts: 249
Joined: Tue Dec 13, 2005 11:08 pm

Post by pedrotuga »

yep... it was exactly what i was looking for.

thanks
Post Reply