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)

 

posted @ 2017-07-14 18:44  MeetU  阅读(2732)  评论(0编辑  收藏  举报