如何将子数组合并到主数组中。
Array
(
[0] => Array
(
[FirmId] => 1
[PartyName] => abc medicals
[PartyCode] => P001
[SalesmanName] =>
)
[1] => Array
(
[FirmId] => 2
[PartyName] => xyz medicals
[PartyCode] => P001
[SalesmanName] =>
)
)
Array
(
[0] => Array
(
[SalesmanName] => abc
)
[1] => Array
(
[SalesmanName] => xyz
)
)
输出应为:
Array
(
[0] => Array
(
[FirmId] => 1
[PartyName] => abc medicals
[PartyCode] => P001
[SalesmanName] => abc
)
[1] => Array
(
[FirmId] => 2
[PartyName] => xyz medicals
[PartyCode] => P001
[SalesmanName] => xyz
)
)
我尝试了 array_merge($ arr1,$ arr2); ,但输出不符合预期。 Merge 2 nested arrays in one with multiple values 这个解决方案太贵了,实际上我的第一个数组有30列,但我只提了4个来简化我的问题。 实际上第二个数组是主数组的切片部分需要合并它。
答案 0 :(得分:-1)
http://php.net/manual/en/function.array-merge-recursive.php
您想使用array_merge_recursive()