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

WBOY
发布: 2016-07-25 09:07:38
原创
822 人浏览过
  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数组排序方法大全



来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!