数组和关联数组合并

Array and Associative Array Merge

如何实现第三个数组,合并Array1和Array2? 在 PHP 中最好的方法是什么?非常感谢。 Array2有like index(key),Array1中id的关联值

数组1

Array
(
    [0] => Array
    (
        [id] => 56
        [grade] => 6.7
    )
    [1] => Array
    (
        [id] => 214
        [grade] => 3.2
    )
)

Array2

Array
(
    [56] => 2.4
    [214] => 5.8 
)

想要的结果

Array
(
    [0] => Array
    (
        [id] => 56
        [grade] => 2.4
    )
    [1] => Array
    (
        [id] => 214
        [grade] => 5.8
    )
)
foreach($array1 as &$arrayItem) {
$arrayItem['grade'] = $array2[$arrayItem['id']]
}

此处您将根据需要合并数组 1