给定PHP中的2个数组,看起来像这样...
Array
(
[item1] => Array
(
[myValues] => Array
(
[1] => 5
[2] => 1
)
)
[item2] => Array
(
[myValues] => Array
(
[1] => 5
[2] => 1
)
)
)
Array
(
[item1] => Array
(
[1] => 2
)
[item2] => Array
(
[1] => 5
[2] => 1
)
)
array1
array ( 'item1' => array ( 'myValues' => array ( 1 => 5, 2 => 1, ), ), 'item2' => array ( 'myValues' => array ( 1 => 5, 2 => 1, ), ), )
将它们组合成如下所示的数组的最佳方法是什么?
Array
(
[item1] => Array
(
[myValues] => Array
(
[1] => 5
[2] => 1
)
[myValues2] => Array
(
[1] => 2
)
)
[item2] => Array
(
[myValues] => Array
(
[1] => 5
[2] => 1
)
[myValues2] => Array
(
[1] => 5
[2] => 1
)
)
)
array2
array ( 'item1' => array ( 1 => 2, ), 'item2' => array ( 1 => 5, 2 => 1, ), )
我无法控制输出,所以我认为我最好的方法是遍历每个数组并将项目复制到一个新的数组中。
我试过了...
print_r(array_merge($a1,$a2));
但这并没有给我带来我想要的结果。有人有例子吗?
慕森王