1

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

1

1 Answer 1

3

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");

Not the answer you're looking for? Browse other questions tagged or ask your own question.