php – 组合两个数组,并按日期排序这个新数组

前端之家收集整理的这篇文章主要介绍了php – 组合两个数组,并按日期排序这个新数组前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
.我有两个数组

第一

Array
    (
        [0] => Array
            (
                [date] => 2012-01-10
                [result] => 65
                [name] => Les océans
            )

        [1] => Array
            (
                [date] => 2012-01-11
                [result] => 75
                [name] => Les mers
            )

        [2] => Array
            (
                [date] => 2012-01-13
                [result] => 66
                [name] => Les continents
                [type] => scores
            )

    )

第二

Array
(
    [0] => Array
        (
            [date_end] => 2012-01-12
            [result] => 60
            [name] => Step#1
            [type] => Summary
        )

)

我想要这个最终结果

Array
        (
            [0] => Array
                (
                    [date] => 2012-01-10
                    [result] => 65
                    [name] => Les océans
                )

            [1] => Array
                (
                    [date] => 2012-01-11
                    [result] => 75
                    [name] => Les mers
                )

             [2] => Array
            (
                [date_end] => 2012-01-12
                [result] => 60
                [name] => Step#1
                [type] => Summary
            )

            [3] => Array
                (
                    [date] => 2012-01-13
                    [result] => 66
                    [name] => Les continents
                    [type] => scores
                )

        )

所以….我需要将我的第一个数组与第二个数组结合起来,我想按日期排序这个新数组!有人可以帮我提示我这样做吗?谢谢 !

array_mergeusort是你的朋友.
function cmp($a,$b){
    $ad = strtotime($a['date']);
    $bd = strtotime($b['date']);
    return ($ad-$bd);
}
$arr = array_merge($array1,$array2);
usort($arr,'cmp');

猜你在找的PHP相关文章