douxi2670 2012-01-31 20:34
浏览 99
已采纳

合并两个数组并按日期顺序排列这个新数组

. I have two array

First One

 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
            )

    )

The second

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

)

And I want this for my final result

 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
                )

        )

So .... I need to combine my first array with the second and I want to order this new array by date !... Can someone can help me on hint me for doing this ? Thx !

  • 写回答

3条回答 默认 最新

  • douzhi4056 2012-01-31 20:46
    关注

    array_merge and usort is your friend.

    function cmp($a, $b){
        $ad = strtotime($a['date']);
        $bd = strtotime($b['date']);
        return ($ad-$bd);
    }
    $arr = array_merge($array1, $array2);
    usort($arr, 'cmp');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器