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

发布时间:2019-09-04编辑:脚本学堂
对多维数组按某值排序的php代码,供大家参考。

对多维数组按某值排序的php代码,供大家参考。
 

复制代码 代码如下:
<?php
    $arr = 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")
                );
    print_r($arr);
    echo "<br />";
    echo "<br />";
    echo "<br />";
    uasort( $arr,create_function('$a, $b', 'return $a['line_num'] < $b['line_num'];') );
    print_r($arr);
    echo "<br />";
    echo "<br />";
    echo "<br />";
    foreach($arr as $key => $value) {
        $ar[] = $value;
    }
    print_r($ar);
?>

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