两个数组,一个数组列出项目,第二个排序第一个,php代码如何?

So I got function that prints out array score which concert clinics:

array_id    clinic_id    score_amount
0             1              5
1             2              1
2             3              5
3             5              3
4             8              2

And i got another function that prints out array clinics id like this: This array is for listing all clinics on page,

array_id    clinic_id
0              1
1              2
2              3
3              4
4              5
5              6
6              7
7              8
8              9
9              10

Now my idea is to make array of clinic_id sorted accordinally to score_amount from first array. And theen if there is no score_amount for particular clinic_id, just go with order from second array normally.

So results needs to be sorted like:

array_id    clinic_id
0              1
1              3
2              5
3              8
4              2
5              4
6              6
7              7
8              9
9              10

use a custom comparator,

function cmp($a, $b)
{
if($a == $b) return 0;   
\\get score returns score or -1 if no score exists
if (getscore($a) == getscore($b) { 
return (index($a) < index($b)) ? -1 : 1;  \\index is index of the number in second array     
}
return (getscore($a) < getscore($b)) ? -1 : 1;
}

usort($a, "cmp");

You could use an associative array (clinic_id => score_amount) and use asort.