I've been banging my head on this one for a while now.
I have this multidimensional array:
Array
(
[0] => Array
(
[0] => foo
[1] => bar
[2] => hello
)
[1] => Array
(
[0] => world
[1] => love
)
[2] => Array
(
[0] => stack
[1] => overflow
[2] => yep
[3] => man
)
And I need to get this:
Array
(
[0] => foo
[1] => bar
[2] => hello
[3] => world
[4] => love
[5] => stack
[6] => overflow
[7] => yep
[8] => man
)
Any ideas?
All other solutions I found solve multidimensional arrays with different keys. My arrays use simple numeric keys only.
In PHP5.6 there other way to solve this problem, combining the functions,
array_shift()
to remove the first elemente of the original array,array_pus()
to add items an new array, the important thing is the of...
splapt/elipse operator it will unpack the return ofarray_shitf()
like an argument.Output:
Example - ideone
I had used this code to resolve same type of problem. so you can also try this.
The PHP
array_merge
Docs function can flatten your array:In case the original array has a higher depth than 2 levels, the SPL in PHP has a
RecursiveArrayIterator
you can use to flatten it:See as well: How to Flatten a Multidimensional Array?.
As of PHP 5.3 the shortest solution seems to be array_walk_recursive() with the new closures syntax:
This will make
RESUTL(ONE DIMENTIONAL ARRAY) :