php - Sorting two arrays so that the second array sorting is based on the first -


i have 2 arrays. first array contains user ids , second array contains number of matched answers against excising data set. size of these arrays same , matched array value indexes correspond of user ids.

useridarr = [1a,2a,3a,4a]; matched = [12,2,5,11]; 

so here user 1a has 12 matched answers, user 2a has 2 , on. how can sort matched array in descending order , @ same time, sort useridarr accordingly. thanks

useridarr = [1a,4a,3a,2a]; matched = [12,11,5,2]; 

you want array_multisort.

array_multisort($matched, $useridarr); 

will sort both arrays require.

array_multisort($matched, sort_desc, $useridarr); 

will sort in descending order required in comment. http://php.net/manual/en/function.array-multisort.php gives lot more information on capabilities of function.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -