Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort a multidimensional array by muliple criterias

Status
Not open for further replies.

hyz74

Technical User
Jun 1, 2005
6
SE
Simplified I've got an array looking like this:

myArray
(
[0] => myArray
(
[0] => Peter
[1] => 45
)

[1] => myArray
(
[0] => Marco
[1] => 46
)

[2] => myArray
(
[0] => Michel
[1] => 45
)

)


I want a final sorted output like this:

Michel 45
Peter 45
Marco 46

How do I do this with php? I'm really struggling with the different sort and array_multisort functions in PHP.

I don't find any help on this anywhere else, it seems like the most common thing to do. Sorting by more than one criteria. First by lowest score and secondly if scores are equal, sort by name ascending.

Would so much appreciate help if available, am on a tight deadline (aren't we all:).

Thanks,
/ Jess
 
You have an array of rows, but array_multisort() requires an array of columns. You can loop through your array and change it to column arrays and then perform the sorting.

If you arrays come from a database, the sorting is best done in the SQL statement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top