Matthew Woodard Matthew Woodard - 1 month ago 4
PHP Question

How to simplify an array with PHP

Seems like a pretty basic question, but how can I simplify an array such as:

Array
(
[0] => Array
(
[blue_dog_1] => 2
)
[1] => Array
(
[red_dog_1] => 4
)
[2] => Array
(
[red_dog_2] => 6
)
)


To be like:

Array
(
[blue_dog_1] => 2
[red_dog_1] => 4
[red_dog_2] => 6
)


Thanks in advance.

Answer

Try this way to make it single dimension from multi dimension using array_merge

$singleD = array_reduce($multiD, 'array_merge', array());

OR

$singleD = call_user_func_array('array_merge', $multiD);