我想按得分最高值对数组顺序进行排序。
它是一个json数据
"score":[
{
"userId":"5",
"playtime":"1396369254",
"score":"25"
},
{
"userId":"1",
"playtime":"1396369056",
"score":"12"
},
{
"userId":"2",
"playtime":"1396369240",
"score":"100"
}
],
这里得分100将是第一个指数
答案 0 :(得分:3)
使用php的函数usort
http://www.php.net/manual/en/function.usort.php
function cmp($a, $b)
{
if ($a['score'] == $b['score']) {
return 0;
}
return ($a['score'] < $b['score']) ? -1 : 1;
}
usort($DATA, "cmp");