是的,array_merge_deep()
函數(shù)在合并數(shù)組時會保留鍵名。這個函數(shù)會遞歸地合并數(shù)組的元素,包括多維數(shù)組,同時保持鍵名不變。下面是一個例子:
$array1 = [
'a' => 1,
'b' => [
'c' => 2,
'd' => 3,
],
];
$array2 = [
'a' => 4,
'b' => [
'e' => 5,
'f' => 6,
],
];
$result = array_merge_deep($array1, $array2);
print_r($result);
輸出結(jié)果:
Array
(
[a] => 4
[b] => Array
(
[c] => 2
[d] => 3
[e] => 5
[f] => 6
)
)
可以看到,array_merge_deep()
函數(shù)保留了原始數(shù)組中的鍵名。