I have a multidimensional array in PHP and I want to un-nest all elements to bring them to the top level. Here is the array:
Array
(
[0] => Array
(
[id] => 1
[color] => red
)
[1] => Array
(
[0] => Array
(
[id] => 2
[color] => blue
)
[1] => Array
(
[0] => Array
(
[id] => 3
[color] => green
)
)
[2] => Array
(
[id] => 4
[color] => blue
)
)
[2] => Array
(
[id] => 5
[color] => purple
)
)
What I want end the end is this... so basically it loops over the array and any group it just unnests it. Sorry, I don't know the proper terminology. Is there PHP function for this? I've tried several solutions on stack but it moves all key values pairs up to the top and not just the array groups --- it just creates a mess.
(
[0] => Array
(
[id] => 1
[id] => red
)
[1] => Array
(
[id] => 2
[color] => blue
)
[2] => Array
(
[id] => 3
[color] => green
)
[3] => Array
(
[id] => 4
[color] => blue
)
[4] => Array
(
[id] => 5
[color] => purple
)
)
Thanks!