欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2024-01-05 22:02:22
...
  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数组排序方法大全