$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值匹配合并到一個數(shù)組中,形成這樣。$c=[
['id'=>1,'age'=>12,'money'=>100],
['id'=>2,'age'=>13,'money'=>200],
['id'=>3,'age'=>15,'money'=>400]
];
2 回答

江戶川亂折騰
TA貢獻1851條經(jīng)驗 獲得超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 關(guān)注
- 2319 瀏覽
添加回答
舉報
0/150
提交
取消