Michał Michał - 1 year ago 64
PHP Question

creating new array from multidimensional arrays -next step

I searched all options for it, without success.

I have my Multidimensional Array like this:

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"
)
)


And I would like to achive result like this:

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"
)
)
)


So I want to add 1 level of array, My thinking way is to loop through multidimensional array(2 loops) and by 3 loop add 2 next(on this example) array within. array_merge_recursive will not work. I tried to create proper loop, but without success. Is it possible??

Answer Source

You can do it like below (Assign both arrays to a new array):-

$arr3 = array($arr1,$arr2); // or [$arr1,$arr2];
print_r($arr3);

Output:-https://eval.in/838283

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download