我搜索了所有选项,没有成功。
我有这样的多维数组:
Array
(
[0] => Array
(
[0] => "Title1"
[1] => "Title2"
[2] => "Title3"
)
[1] => Array
(
[0] => "Title1"
[1] => "Title2"
)
)
Array #2
Array
(
[0] => Array
(
[0] => "Value1"
[1] => "Value2"
[2] => "Value3"
)
[1] => Array
(
[0] => "Value"
[1] => "Value2"
)
)
我想得到这样的结果:
New Array
Array
(
[0] => Array
(
[0] =>Array
(
[0] => "Title1"
[1] => "Title2"
[2] => "Title3"
)
(
[1] =>Array
(
[0] => "Title1"
[1] => "Title2"
)
)
(
[1] => Array
(
[0] =>Array
(
[0] => "Value1"
[1] => "Value2"
[2] => "Value3"
)
(
[1] =>Array
(
[0] => "Value"
[1] => "Value2"
)
)
)
所以我想添加1级数组,我的想法是循环遍历多维数组(2个循环),然后通过3个循环添加2个下一个(在此示例中)数组。 array_merge_recursive不起作用。我试图创建适当的循环,但没有成功。有可能??
答案 0 :(得分:2)
您可以像下面这样( 将两个数组分配到新数组 ): -
$arr3 = array($arr1,$arr2); // or [$arr1,$arr2];
print_r($arr3);
输出: - https://eval.in/838283
答案 1 :(得分:1)
试试这个 -
$finalArray=[$arr1,$arr2]
然后你可以添加更多像
这样的数组 $finalArray[] = $arr3;
答案 2 :(得分:0)
使用array_merge()函数
array_merge(array1,array2);