2

我有一个以下格式的关联数组。我需要按降序对数组进行排序,并以与升序相同的值对数组进行排序。

$numArray = array();
$numArray[0]['Word'] = 'One';
$numArray[0]['Number'] = 10.00;
$numArray[1]['Word'] = 'Two';
$numArray[1]['Number'] = 10.00;
$numArray[2]['Word'] = 'Three';
$numArray[2]['Number'] = 10.00; 
$numArray[3]['Word'] = 'Four';
$numArray[3]['Number'] = 30.00;
$numArray[4]['Word'] = 'Five';
$numArray[4]['Number'] = 20.00; 
$numArray[5]['Word'] = 'Six';
$numArray[5]['Number'] = 10.00; 
$numArray[6]['Word'] = 'Seven';
$numArray[6]['Number'] = 20.00; 
$numArray[7]['Word'] = 'Eight';
$numArray[7]['Number'] = 20.00;

请帮我按以下顺序对数组进行排序。

数组 ( [0] => 数组 ( [Word] => 四 [Number] => 30 )

        [1] => Array
            (
                [Word] => Five
                [Number] => 20
            )

        [2] => Array
            (
                [Word] => Seven
                [Number] => 20
            )

        [3] => Array
            (
                [Word] => Eight
                [Number] => 20
            )

        [4] => Array
            (
                [Word] => One
                [Number] => 10
            )

        [5] => Array
            (
                [Word] => Two
                [Number] => 10
            )

        [6] => Array
            (
                [Word] => Three
                [Number] => 10
            )

        [7] => Array
            (
                [Word] => Six
                [Number] => 10
            )

    )
4

1 回答 1

0
foreach ($numArray as $key => $row) {
    $array[$key]  = $row['Number']; 
}


array_multisort($array, SORT_DESC, $numArray);

这个小 php 代码至少会根据 Number 对数组 desc 进行排序。猜猜这就是你想要的一半。

于 2013-08-27T15:30:56.393 回答