Reputation: 11
I want to sort my array order by highest value of score.
it's a json data
"score":[
{
"userId":"5",
"playtime":"1396369254",
"score":"25"
},
{
"userId":"1",
"playtime":"1396369056",
"score":"12"
},
{
"userId":"2",
"playtime":"1396369240",
"score":"100"
}
],
here score 100 will be first index
Upvotes: 1
Views: 132
Reputation: 6381
use php's function 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");
Upvotes: 3