你怎么能合并两个数组? [英] How can you combine two arrays?
本文介绍了你怎么能合并两个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它们如下这是足以为这个问题简化。这个问题是基于<一个href=\"http://stackoverflow.com/questions/1281007/to-understand-an-array-in-php-when-given-the-other-variable-in-the-array/1281015#1281015\">this回答。
1
[A] [B] []
和
2
[A] [C]
,其中两个数组都有一个共同的子阵[A]。
我想有这样的
[A] [C] [B] []
我已经失败运行下面的命令
数组1 [A] +数组2 [一]
解决方案
的foreach($数组1为$ a =&GT; $ C)
{
$ end_array [$ C = $数组2 [$一];
}
或
//对于每一个[一]
的foreach($数组1为$ a =&GT; $ C)
{
//获取[B]
$ B = $数组2 [$一]; //将它添加到[A] [C]
$ end_array [$一] [$ C = $ B; //使之成为$ end_array [$一] [$ C] [$ B] =阵列(....);
}
They are simplified as follows which is enough for this question. This question is based on this answer.
1
[a][b][]
and
2
[a][c]
where both arrays has one common subarray [a].
I would like to have this
[a][c][b][]
I have run the following command unsuccessfully
array1[a] + array2[a]
解决方案
foreach($array1 as $a => $c)
{
$end_array[$c] = $array2[$a];
}
or
// For every [a]
foreach($array1 as $a => $c)
{
// Get the [b]
$b = $array2[$a];
// Add it to [a][c]
$end_array[$a][$c] = $b;
// Making it $end_array[$a][$c][$b] = array(....);
}
这篇关于你怎么能合并两个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文