Jump to content

Sorting Multidimensional Array


max1234

Recommended Posts

Hi,

 

I need to sort a multidimensional array. I know this should be very simple but am having some difficulty wrapping my head around it.

 

I have an array of arrays containing order information. In each array there is a field for product name and I would like to sort the arrays by product name.

 

So for example:

 

$myarray[1,shoes]

$myarray[2,wellies]

$myarray[3,boots]

$myarray[4,wellies]

 

How do I sort $myarray so that it is ordered alphabetically?

 

 

$myarray[3,boots]

$myarray[1,shoes]

$myarray[2,wellies]

$myarray[4,wellies]

 

I have tried sort and multisort but how do choose which variable to sort by? I don't want to sort by the number, I want to sort by the product name.

 

Thanks for any help.

Link to comment
https://forums.phpfreaks.com/topic/271175-sorting-multidimensional-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.