Sorting Array by Another
Posted on 2011-10-08
I know this has been asked many times but I don't understand the answers...
Basically I have two arrays.
The first is $wordlist and contains a list of words. (e.g. $wordlist='hello'; $wordlist='bye';)
The second is $weight and contains a list of numbers where each value is the weight of the corresponding word from $wordlist with the same array number. (e.g. $weight=100; $weight=150;)
So I just want to sort the $wordlist array by the $weight array so that the highest weight is first. Actually I only want to find the highest weight, it's not totally necessary to return the full list.
I could just loop through the array to find the highest, but I don't want to do this because $wordlist is very long and the function is called a lot, so that would slow down the script. Better to use a quicksort implementation (such as the PHP built-in sorts).
How would I do this?