首頁 > 後端開發 > php教程 > 對多維數組依某值排序的php程式碼

對多維數組依某值排序的php程式碼

WBOY
發布: 2016-07-25 09:07:38
原創
845 人瀏覽過
  1. $arr = array(
  2. "0" => array(line_num => "10", occur_time => "2007-11-19 10:25:04+08"),
  3.    "1" => array(line_num => "9", occur_time => "2007-11-19 10:25:04+08"),
  4.  "2" => array(line_num => "25", occur_time => "2007-11-19 10:25:04+08")
  5. );
  6. print_r($arr);
  7. echo "
    ";
  8. echo "
    ";
  9. echo "
    ";
  10. uasort( $arr,create_function('$a, $b', 'return $a['line_num'] < $b['line_num'];') );
  11. print_r($arr);
  12. echo "
    ";
  13. echo "
    ";
  14. echo "
    ";
  15. foreach($arr as $key => $value) {
  16. $ar[] = $value;
  17. }
  18. print_r($ar);
  19. ?>
复制代码

输出结果: Array ( [0] => Array ( [line_num] => 10 [occur_time] => 2007-11-19 10:25:04+08 ) [1] => Array ( [line_num] => 9 [occur_time] => 2007-11-19 10:25:04+08 ) [2] => Array ( [line_num] => 25 [occur_time] => 2007-11-19 10:25:04+08 ) )


Array ( [2] => Array ( [line_num] => 25 [occur_time] => 2007-11-19 10:25:04+08 ) [0] => Array ( [line_num] => 10 [occur_time] => 2007-11-19 10:25:04+08 ) [1] => Array ( [line_num] => 9 [occur_time] => 2007-11-19 10:25:04+08 ) )


Array ( [0] => Array ( [line_num] => 25 [occur_time] => 2007-11-19 10:25:04+08 ) [1] => Array ( [line_num] => 10 [occur_time] => 2007-11-19 10:25:04+08 ) [2] => Array ( [line_num] => 9 [occur_time] => 2007-11-19 10:25:04+08 ) )

>>> 更多内容,请查看 php数组排序方法大全



來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板