首页 > 代码库 > PHP合并 两个二维数组
PHP合并 两个二维数组
$a = array( array(‘id‘=>‘113‘,‘email‘=>‘yintx_1292342352@163.com‘), array(‘id‘=>‘111‘,‘email‘=>‘yintx_1293456456@163.com‘), array(‘id‘=>‘109‘,‘email‘=>‘yintx_129@99999.com‘) ); $b = array( array(‘user_id‘=>‘113‘,‘count‘=>‘1‘), array(‘user_id‘=>‘109‘,‘count‘=>‘8‘) ); foreach($a as $ka=>$va){ foreach($b as $kb=>$vb){ if($va[‘id‘] == $vb[‘user_id‘]){ $a[$ka][‘count‘] = $vb[‘count‘]; } } } var_dump($a); ---------- array (size=3) 0 => array (size=3) ‘id‘ => string ‘113‘ (length=3) ‘email‘ => string ‘yintx_1292342352@163.com‘ (length=24) ‘count‘ => string ‘1‘ (length=1) 1 => array (size=2) ‘id‘ => string ‘111‘ (length=3) ‘email‘ => string ‘yintx_1293456456@163.com‘ (length=24) 2 => array (size=3) ‘id‘ => string ‘109‘ (length=3) ‘email‘ => string ‘yintx_129@99999.com‘ (length=19) ‘count‘ => string ‘8‘ (length=1)
PHP合并 两个二维数组
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。