我有两个数组
第一个数组
(
[0] => Array
(
[352] => 1
[128] =>
[64] =>
[70] => 2
)
)
第二个数组是这样的:
Array
(
[0] => Array
(
[128] => 1.5
)
)
我想像这样制作最终数组。(我想在这个例子中将匹配存储到主数组中,它是 128 -> 1.5 )我该怎么做。?
Array
(
[0] => Array
(
[352] => 1
[128] => 1.5
[64] =>
[70] => 2
)
)
这是我的数组变量:
print_r($listskilssresult);
print_r($listskilssresultmatching);
最佳答案
您需要使用 array_replace_recursive
$listskilssresult = [
[
352 => 1,
128 => '',
64 => '',
70 => 2
]
];
$listskilssresultmatching = [
[
128 => 1.5
]
];
print_r(array_replace_recursive($listskilssresult, $listskilssresultmatching));
打印:
Array
(
[0] => Array
(
[352] => 1
[128] => 1.5
[64] =>
[70] => 2
)
)
知道
array_replace_recursive
之间的区别和 array_merge_recursive
here
关于php - 合并两个数组,替换相同键的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44878652/