-1
我有兩個數組,我想匹配第一個數組的鍵與另一個數組,如果兩個鍵匹配的值然後將第二個數組的值添加到數組1匹配數組值併合並,如果值匹配在PHP中
陣列1
[{"currency":1,"amount":23},{"currency":1,"amount":30},{"currency":2,"amount":40},]
陣列2
[{"currency_id": 1,"currency_symbol":$},{"currency_id":2,"currency_symbol":€}]
所需的輸出是:
[{"currency":$,"amount":23},{"currency":$,"amount":30},{"currency":€,"amount":40}]
我使用的代碼是:
foreach($a1 as $key) {
foreach($a2 as $cKey){
if($a1['currency']==$a2['currency_id']){
$a1['currency_symbol'] = $a2['currency_symbol'];
echo $a1['currency_symbol'];
}
}
}
你的問題是什麼? –
到目前爲止,您已經實現了哪些目標來實現所需的輸出? –
我試着用foreach循環,但我不知道要與其他數組匹配鍵值, – mohit