2012-02-18 168 views
-1

如果我有這樣的數組:PHP多排序陣列

array(
    [0] => array(5, "hi"), 
    [1] => array(2, "hello"), 
    [2] => array(9, "test") 
) 

我如何排序這個數組由[N] [0]?
最終結果應該是這樣的:

array(
    [0] => array(9, "test") 
    [1] => array(5, "hi"), 
    [2] => array(2, "hello"), 
) 
+1

可能重複[如何排序在第4級值多維數組PHP(http://stackoverflow.com/questions/2673835/how-to-sort-a-multi-dimensional-array-by-a-4th-level-value-in-php) – 2012-02-18 00:30:00

回答

0

您可以使用自定義的比較函數:

function multi_sort($a, $b) 
{ 
    return $a[0] < $b[0]; 
} 

usort($array, 'multi_sort');