Sorting a 3D array

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
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Sorting a 3D array

Post by impulse() »

I have an array that looks like:

Code: Select all

$array['a'][0] = 120;
$array['b'][1] = 130;
$array['c'][2] = 140;
$array['a'][0] = 150;
$array['b'][1] = 160;
I want to sort the array descendingly by the values in $array['b'] but I want all the other values to sorted along with those.
I understand that my description isn't very good and please let me know if you don't understand.

Regards,
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Not to worry regarding this, MySQL was able to do the sorting. Please go ahead an answer if you know anyway as I'm interested to know how this would be solved without MySQL.

Regards,
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

It looks like you have a duplicate entries in your array.

Just provide an example of array that you have and desired order after sort.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That's a 2D array.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I thought there was an example on that page that showed how to break a 3D down to 2D as you run the 2D through this function. I could be wrong. I used a modified hack of that function a while back to wrangle 2d and 3d arrays on multiple fields (like sorting within a sort). But I could be just plain wrong.
Post Reply