Page 1 of 1

Sorting multidimensional array

Posted: Thu May 20, 2004 4:57 am
by thepiglet
Hi,
Big problems here. I can't for the life of me get this thing to sort numerically. Here's a sample array:


$order[sandwich][45678][3][0][text] = 'Butter';
$order[sandwich][45678][1][0][text] = 'Cheddar Cheese';
$order[sandwich][45678][0][0][text] = 'Bread';
$order[sandwich][45678][1][1][text] = 'Leicester Cheese';
$order[sandwich][45678][9][0][text] = 'Pickle';

As you will see, the array takes the following steps:

sandwich- this means it is processed by the sandwichfunctions in the basket.
45678 - this is the unique ID for this sandwich.
1,3,0,9 - these are the category IDs of the components such as Cheeses stored in a mysql table.
0,0,0,1,0 - these are incremental so you can have more than one type of cheese for example.
text - this is the descriptive name for the component, others include ID which links to the item in a db.

OK, what I'm trying to do is sort this array by the 1,3,0,9 values (so it goes bread, cheese, butter, pickle) but am having no luck!
All the data is being messed up and I'm getting nowhere. Remember the can be other food types such as 'rolll', further 'roll' IDs etc..

Any ideas?

Posted: Thu May 20, 2004 5:02 am
by patrikG
use [php_man]array_multisort[/php_man], have a look at the user-notes there.

Posted: Thu May 20, 2004 6:22 am
by launchcode
Yeah, it cannot be done with a single PHP command - I would recommend the Ichier function on the page patrik posted above, very handy indeed.

Posted: Thu May 20, 2004 10:06 am
by thepiglet
OK,
Thanks for the advice. I was bumbling around with array_multisort but didn't get as far as the notes :o)
I'll let you know how I get on.