$a= [
['id'=>1,'age'=>12],
['id'=>2,'age'=>13],
['id'=>3,'age'=>15]
];$b= [
['id'=>1,'money'=>100],
['id'=>3,'money'=>400],
['id'=>2,'money'=>200]
];怎么按照id值匹配合并到一个数组中,形成这样。$c=[
['id'=>1,'age'=>12,'money'=>100],
['id'=>2,'age'=>13,'money'=>200],
['id'=>3,'age'=>15,'money'=>400]
];
2 回答
江户川乱折腾
TA贡献1851条经验 获得超5个赞
$a = [ ['id' => 1, 'age' => 12], ['id' => 2, 'age' => 13], ['id' => 3, 'age' => 15] ]; $b = [ ['id' => 1, 'money' => 100], ['id' => 2, 'money' => 200], ['id' => 3, 'money' => 400], ]; $c = [];foreach ($a as $_a) { $_c = $_a; foreach ($b as $_b) { if ($_a['id'] === $_b['id']) { $_c['money'] = $_b['money']; } } $c[] = $_c; } print_r($c);
- 2 回答
- 0 关注
- 2283 浏览
添加回答
举报
0/150
提交
取消