Sorting arrays with mixed elements

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
zduniacz
Forum Newbie
Posts: 3
Joined: Tue Jun 15, 2010 2:04 pm

Sorting arrays with mixed elements

Post by zduniacz »

Hi,

I have an array with the following structure: char char integer.

I mean, when I print it get these example results:

POL LIPA 18
USA JOHNSON 21
FRA LIERRE 14

So, I would like this list to be sorted from the highest INT variable to the lowest, so I would get:
USA JOHNSON 21
POL LIPA 18
FRA LIERRE 14

I was able to use sort(); with arrays with the elements of same type but I think it wont work here?

Thanks for all help.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Sorting arrays with mixed elements

Post by andyhoneycutt »

This thread may help you out: viewtopic.php?f=1&t=117537
zduniacz
Forum Newbie
Posts: 3
Joined: Tue Jun 15, 2010 2:04 pm

Re: Sorting arrays with mixed elements

Post by zduniacz »

Thanks mate, array_multisort() was exactly what I was looking for.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Sorting arrays with mixed elements

Post by andyhoneycutt »

Excellent!
Post Reply