PHP合并两个数组
问题描述:
我有两个数组,我想这两个数组合并成一个阵列。请查看下面的细节:
I have two arrays, I want to merge these two arrays into single array. Please view the detail below:
第一个数组:
Array
(
[0] => Array
(
[a] => 1
[b] => 2
[c] => 3
)
[1] => Array
(
[a] => 3
[b] => 2
[c] => 1
)
)
第二个数组:
Array
(
[0] => Array
(
[d] => 4
[e] => 5
[f] => 6
)
[1] => Array
(
[d] => 6
[e] => 5
[f] => 4
)
)
我想这个结果。是否有人知道如何做到这一点?
I want this result. Does somebody know how to do this?
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[1] => Array
(
[0] => 3
[1] => 2
[2] => 1
)
[2] => Array
(
[0] => 4
[1] => 5
[2] => 6
)
[3] => Array
(
[0] => 6
[1] => 5
[2] => 4
)
)
希望你有明白的问题。
谢谢你在前进。
Hope you have understand the question. Thank you in advance.
答
固定(再次)
function array_merge_to_indexed () {
$result = array();
foreach (func_get_args() as $arg) {
foreach ($arg as $innerArr) {
$result[] = array_values($innerArr);
}
}
return $result;
}
接受输入数组的数量不受限制,合并所有子阵列到一个容器中作为索引的数组,并返回结果。
Accepts an unlimited number of input arrays, merges all sub arrays into one container as indexed arrays, and returns the result.
的 修改03/2014:的提高可读性和效率
EDIT 03/2014: Improved readability and efficiency