Jump to content

Sorting Array Based on Multiple Parameters


rsnider19

Recommended Posts

I am working on some software so I hope I can get my problem across without divulging too much about it.  Basically, I have an associative array which links a word to an array with some information about the word.  How can I sort the associative array based on two pieces of information in the nested array?  Say info1 ascending and info2 descending.  I kind of found some information for Java, but I can't quite figure out how to port it to php.

Hi

 

You can use usort. It will pass each array member in turn to a function you write, and in your case each array member is itself an array, hence you decide which of the sub arrays are compared in which order to decide which is the larger / smaller.

 

All the best

 

Keith

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.