views:

72

answers:

2

I have array like

Array ( [608665839] => Array ( [score] => 2 ) [1756044141] => Array ( [score] => 5 ) [523536777] => Array ( [score] => 2 ) )

and I want to sore this array by score. How can I do?

+2  A: 

I would use uasort

Myles
I would too. It's very easy.
Peter Lindqvist
A: 

From PHP.net:

<?php
    function order_array_num ($array, $key, $order = "ASC")
    {
        $tmp = array();
        foreach($array as $akey => $array2)
        {
            $tmp[$akey] = $array2[$key];
        }

        if($order == "DESC")
        {arsort($tmp , SORT_NUMERIC );}
        else
        {asort($tmp , SORT_NUMERIC );}

        $tmp2 = array();       
        foreach($tmp as $key => $value)
        {
            $tmp2[$key] = $array[$key];
        }       

        return $tmp2;
    }
?>

$order = "ASC" will sort the array in an ascending order while $order = "DESC" will sort the array in a descending order.

Hope this helps.

FreekOne