数组$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
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; } } } }
2个嵌套循环或者,去看看array_search 和array_column的相关知识吧!- -同样的问题你居然发了2个贴。好拼!