Php 从其他多维数组替换多维数组中的值

Php 从其他多维数组替换多维数组中的值,php,arrays,Php,Arrays,有人知道如何用第二个数组中的值替换第一个数组中的快捷方式吗 $first_array = [ 'product 1' => ['name 1', 'shortcut 1'], 'product 2' => ['name 2', 'shortcut 2'] ]; $second_array = [ 'product 1' => ['shortcut 1' => 'text 1'], 'product 2' => ['shortcut 2' => 'text 2

有人知道如何用第二个数组中的值替换第一个数组中的快捷方式吗

$first_array = [
'product 1' => ['name 1', 'shortcut 1'],
'product 2' => ['name 2', 'shortcut 2']
];

$second_array = [
'product 1' => ['shortcut 1' => 'text 1'],
'product 2' => ['shortcut 2' => 'text 2']
];


// Do not work.
$new_array = array_replace($first_array, $second_array);
我需要这样的输出

$new_array = [
'product 1' => ['name 1' => 'text 1'],
'product 2' => ['name 2' => 'text 2']
]

尝试将其替换为带有检查键和值的foreach循环

$first_array = [
'product 1' => ['name 1' => 'shortcut 1'],
'product 2' => ['name 2' => 'shortcut 2']
];

$second_array = [
'product 1' => ['shortcut 1' => 'text 1'],
'product 2' => ['shortcut 2' => 'text 2']
];
$new_array = array();
foreach($first_array as $key=>$value)
{
    foreach($value as $key1=>$value1)
    {
        if(isset($second_array[$key][$value1]))
        $new_array[$key][$key1]=$second_array[$key][$value1];
    }
}
print_r($new_array);