Page 1 of 1

Sorting a 3D array

Posted: Wed Apr 18, 2007 9:08 am
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,

Posted: Wed Apr 18, 2007 9:15 am
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,

Posted: Wed Apr 18, 2007 9:17 am
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.

Posted: Wed Apr 18, 2007 10:47 am
by RobertGonzalez

Posted: Wed Apr 18, 2007 3:59 pm
by feyd
That's a 2D array.

Posted: Wed Apr 18, 2007 4:25 pm
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.