慕婉清6462132
$a = [
['id'=>'1', 'name'=>'北京'],
['id'=>'2', 'name'=>'上海'],
['id'=>'3', 'name'=>'黄州'],
];
$b = [
['id'=>'111', 'name'=>'北京'],
['id'=>'333', 'name'=>'黄州'],
];
//一对一
for ($i=0; $i < count($a); $i++) {
$c[$i] = $a[$i];
$c[$i]['num'] = $b[$i]['id'];
}
var_dump($c);
//a为主
foreach ($a as $key => $value) {
$d[$key] = $value;
foreach ($b as $keyt => $valuet) {
if($value['name'] == $valuet['name']){
$d[$key]['num'] = $valuet['id'];
unset($b[$keyt]);
continue;
}
}
}
var_dump($d);die;