Rumah >pembangunan bahagian belakang >tutorial php >对多维数组按某值排序的php代码

对多维数组按某值排序的php代码

WBOY
WBOYasal
2016-07-25 09:07:38850semak imbas
  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\'] print_r($arr);
  11. echo "
    ";
  12. echo "
    ";
  13. echo "
    ";
  14. foreach($arr as $key => $value) {
  15. $ar[] = $value;
  16. }
  17. print_r($ar);
  18. ?>
复制代码

输出结果: 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数组排序方法大全



Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn