php 怎样把有一个相同字段的数组重组一个数组

拿时间做一个栗子: 

$data = Array
(
    [0] => Array
        (
            [user_id] => 14
            [agent_id] => 2
            [nickname] => 匿名
            [username] => D5VCDP
            [refman] => 
            [refid] => 0
            [promoter_id] => 0
            [apply_time] => 2019-05-12 10:00:38
        )

    [1] => Array
        (
            [user_id] => 16
            [agent_id] => 2
            [nickname] => 匿名
            [username] => 3VD4NC
            [refman] => D5VCDP
            [refid] => 13
            [promoter_id] => 0
            [apply_time] => 2019-04-12 10:05:35
        )

    [2] => Array
        (
            [user_id] => 17
            [agent_id] => 2
            [nickname] => 匿名
            [username] => DC1MCU
            [refman] => D5VCDP
            [refid] => 13
            [promoter_id] => 0
            [apply_time] => 2019-04-12 10:05:40
        )

    [3] => Array
        (
            [user_id] => 19
            [agent_id] => 2
            [nickname] => 匿名
            [username] => 8OJDCE
            [refman] => DC1MCU
            [refid] => 16
            [promoter_id] => 0
            [apply_time] => 2019-04-12 10:05:50
        )

    [4] => Array
        (
            [user_id] => 20
            [agent_id] => 2
            [nickname] => 匿名
            [username] => Q71I3G
            [refman] => 
            [refid] => 0
            [promoter_id] => 0
            [apply_time] => 2019-03-12 14:19:31
        )

)




        $result=[];
        foreach($data as $value){
            $result[date('Y-m-d',strtotime($value["apply_time"]))][]=[
                'user_id'=>$value['user_id'],
                'agent_id'=>$value['agent_id'],
                'nickname'=>$value['nickname'],
                'username'=>$value['username'],
                'refman' => $value['refman'],
                'refid' => $value['refid'],
                'promoter_id' => $value['promoter_id'],
                'apply_time'=>$value['apply_time'],
            ];
        }
        print_r($result);exit; 

 

打印结果:

Array
(
    [2019-05-12] => Array
        (
            [0] => Array
                (
                    [user_id] => 14
                    [agent_id] => 2
                    [nickname] => 匿名
                    [username] => D5VCDP
                    [refman] => 
                    [refid] => 0
                    [promoter_id] => 0
                    [apply_time] => 2019-05-12 10:00:38
                )

        )

    [2019-04-12] => Array
        (
            [0] => Array
                (
                    [user_id] => 16
                    [agent_id] => 2
                    [nickname] => 匿名
                    [username] => 3VD4NC
                    [refman] => D5VCDP
                    [refid] => 13
                    [promoter_id] => 0
                    [apply_time] => 2019-04-12 10:05:35
                )

            [1] => Array
                (
                    [user_id] => 17
                    [agent_id] => 2
                    [nickname] => 匿名
                    [username] => DC1MCU
                    [refman] => D5VCDP
                    [refid] => 13
                    [promoter_id] => 0
                    [apply_time] => 2019-04-12 10:05:40
                )

            [2] => Array
                (
                    [user_id] => 19
                    [agent_id] => 2
                    [nickname] => 匿名
                    [username] => 8OJDCE
                    [refman] => DC1MCU
                    [refid] => 16
                    [promoter_id] => 0
                    [apply_time] => 2019-04-12 10:05:50
                )

        )

    [2019-03-12] => Array
        (
            [0] => Array
                (
                    [user_id] => 20
                    [agent_id] => 2
                    [nickname] => 匿名
                    [username] => Q71I3G
                    [refman] => 
                    [refid] => 0
                    [promoter_id] => 0
                    [apply_time] => 2019-03-12 14:19:31
                )

        )

)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值