本文介绍了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
这篇关于PHP合并两个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!