2013-02-21 186 views
0

我正面臨與陣列排序有關的問題。我想根據這些點來排序這個數組。請幫幫我,感謝名單提前多維數組排序?

Array 
(
[5] => Array 
    (
     [0] => Array 
      (
       [feedbacks] => Array 
        (
         [emp_name] => test test 
        ) 

       [0] => Array 
        (
         [point] => 19 
        ) 
      ) 
    ) 

[9] => Array 
    (
     [0] => Array 
      (
       [feedbacks] => Array 
        (
         [emp_name] => a 
        ) 

       [0] => Array 
        (
         [point] => 5 
        ) 
      ) 
    ) 

[8] => Array 
    (
     [0] => Array 
      (
       [feedbacks] => Array 
        (
         [emp_name] => b 
        ) 

       [0] => Array 
        (
         [point] => 23 
        ) 
      ) 
    ) 

[4] => Array 
    (
     [0] => Array 
      (
       [feedbacks] => Array 
        (
         [emp_name] => c 

       [0] => Array 
        (
         [point] => -1 
        ) 
      ) 
    ) 

+0

重複:請找出這個問題的解決方案: http://stackoverflow.com/questions/14873434/sort-php-array-by-multiple-options/14873638#14873638 and http://stackoverflow.com/questions/2699086/sort-multidimensional-array-by-value-2 – Prabu 2013-02-21 10:27:05

回答

0

試試這個:

<?php 

$arr='Your array'; 


$sort = array(); 
foreach($arr as $k=>$v) { 
    $sort['point'][$k] = $v[0][0]['point']; // $v[0][0] is your point for each array 
} 

array_multisort($sort['point'], SORT_DESC, $arr); 
///array_multisort($sort['point'], SORT_ASC, $arr); // for ascending order 

echo "<pre>"; 
print_r($arr); 

?> 
+0

有一個我編輯的小問題代碼。 – 2013-02-21 10:33:06