首页新闻找找看学习计划

PHP数组操作求助

0
悬赏园豆:100 [已解决问题] 解决于 2016-06-21 13:15
复制代码
数组$result=
Array
(
    [0] => Array
        (
            [id] => 5
            [activity_id] => 2
            [applyid] => 5
            [signedtime] => 1463056434
            [typeid] => 1
            [name] => 王
            [mobile] => 
        )

    [1] => Array
        (
            [id] => 8
            [activity_id] => 2
            [applyid] => 5
            [signedtime] => 1463074455
            [typeid] => 3
            [name] => 王
            [mobile] => 
        )

    [2] => Array
        (
            [id] => 16
            [activity_id] => 2
            [applyid] => 6
            [signedtime] => 1463036123
            [typeid] => 4
            [name] => zhang
            [mobile] => 
        )

)


数组$signedtime=
Array
(
    [0] => Array
        (
            [id] => 1
            [activityid] => 2
            [activityname] => 测试数据2多次签到
            [signedname] => 一次签到
            [create_time] => 1465181547
            [listorder] => 0
            [sign_img] => 
            [type] => 
        )

    [1] => Array
        (
            [id] => 3
            [activityid] => 2
            [activityname] => 测试数据2多次签到
            [signedname] => 二次签到
            [create_time] => 1465182225
            [listorder] => 0
            [sign_img] => 
            [type] => 
        )

    [2] => Array
        (
            [id] => 4
            [activityid] => 2
            [activityname] => 测试数据2多次签到
            [signedname] => 三次签到
            [create_time] => 1465189536
            [listorder] => 0
            [sign_img] => 
            [type] => 
        )

)




要求结果:
Array
(
    [0] => Array
        (
            [activity_id] => 2
            [name] => 王
            [mobile] => 
            [signed] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 一次签到
                            [create_time] => 1465181547
                            [listorder] => 0
                            [sign_img] => 
                            [type] => 
                            [time] =>1463056434
                        )

                    [1] => Array
                        (
                            [id] => 3
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 二次签到
                            [create_time] => 1465182225
                            [listorder] => 0
                            [sign_img] => 
                            [type] => 
                            [time] =>1463074455
                        )

                    [2] => Array
                        (
                            [id] => 4
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 三次签到
                            [create_time] => 1465189536
                            [listorder] => 0
                            [sign_img] => 
                            [type] =>
                            [time]=> 
                        )            

                )

        )

    [1] => Array
        (
            [activity_id] => 2
            [name] => zhang
            [mobile] => 
            [signed] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 一次签到
                            [create_time] => 1465181547
                            [listorder] => 0
                            [sign_img] => 
                            [type] => 
                            [time] =>
                        )

                    [1] => Array
                        (
                            [id] => 3
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 二次签到
                            [create_time] => 1465182225
                            [listorder] => 0
                            [sign_img] => 
                            [type] =>
                            [time] =>
                        )

                    [2] => Array
                        (
                            [id] => 4
                            [activityid] => 2
                            [activityname] => 测试数据2多次签到
                            [signedname] => 三次签到
                            [create_time] => 1465189536
                            [listorder] => 0
                            [sign_img] => 
                            [type] => 
                            [time]=>1463036123
                        )

                   
                )

        )

)

其中$result中applyid相同的合并,$result中的replyid等于$signedname中的id
复制代码
幻月无痕的主页 幻月无痕 | 初学一级 | 园豆:105
提问于:2016-06-20 14:50
< >
分享
最佳答案
0
 for($i=0;$i<count($new_rst);$i++){
            for($j=0;$j<count($new_rst[$i]['signed']);$j++){
                for($k=0;$k<count($result);$k++){
                    if($new_rst[$i]['signed'][$j]['id']==$result[$k]['typeid'] && $new_rst[$i]['name']==$result[$k]['name']){
                        $new_rst[$i]['signed'][$j]['time']=$result[$k]['signedtime'];
                        break;
                    }
                }
            }
        }   

 

幻月无痕 | 初学一级 |园豆:105 | 2016-06-21 13:14
其他回答(1)
0

2个嵌套循环或者,去看看array_search 和array_column的相关知识吧!- -同样的问题你居然发了2个贴。好拼!

收获园豆:100
贫民窟大侠 | 园豆:4270 (老鸟四级) | 2016-06-20 17:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册