usort() 用户自定义排序的实现
-
function
multi_compare(
$a
,
$b
)
-
{
-
$criteria
=
array
(
-
‘gold’
=>
‘desc’
,
-
‘ts’
=>
‘desc’
//这里还可以根据需要继续加条件 如:’x’=>’asc’等
-
);
-
foreach
(
$criteria
as
$what
=>
$order
){
-
if
(
$a
[
$what
] ==
$b
[
$what
]){
-
continue
;
-
}
-
return
((
$order
==
‘desc’
)?-1:1) * ((
$a
[
$what
] <
$b
[
$what
]) ? -1 : 1);
-
}
-
return
0;
-
}
-
usort(
$sorted_array
,
“multi_compare”
);