lacyeex lacyeex - 3 months ago 20
PHP Question

Change multidimensional array structure PHP

I have a set of array from combining 2 variables of array, and the output is like this :

Array
(
[0] => Array
(
[0] => 3
[1] => 1
)
[1] => Array
(
[0] => Array
(
[0] => 4
[1] => 7
)

[1] => Array
(
[0] => 20
[1] => 10
)
)
)


But i want to change the structure, so the array will be like this :

Array
(
[0] => Array
(
[0] => 3
[1] => 1
)
[1] => Array
(
[0] => 4
[1] => 7
)
[2] => Array
(
[0] => 20
[1] => 10
)
)


Is there anyway to change the structure?
*edit I used code below to combining both array :

$newarray = array($array1, $array2)

Answer

It sounds like you could use array_merge instead.

$new_array = array_merge([$array1], $array2);
Comments