I'm looking to find a way to merge all child arrays into one large array.
array (
[0] =
[0] = '0ARRAY',
[1] = '1ARRAY'
[1] =
[0] = '2ARRAY',
[1] = '3ARRAY'
)
into
array (
[0] = '0ARRAY', [1] = '1ARRAY', [2] = '2ARRAY', [3] = '3ARRAY'
)
Without using array_merge($array[0],$array[1])
because I don't know how many arrays there actually are. So I wouldn't be able to specify them.
Thanks
If I understood your question:
php 5.6+
$array = array(
array('first', 'second'),
array('next', 'more')
);
$newArray = array_merge(...$array);
Outputs:
array(4) { [0]=> string(5) "first" [1]=> string(6) "second" [2]=> string(4) "next" [3]=> string(4) "more" }
Example: http://3v4l.org/KA5J1#v560
php < 5.6
$newArray = call_user_func_array('array_merge', $array);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With