This question already has an answer here:
What is the best way to merge a 2-dimensional array into a 1-dimensional array?
Source Array:
$example = array(
array(
'red',
'green'
),
array(
'blue',
'brown'
),
array(
'yellow'
)
);
Required Output Array:
$output = array(
'red',
'green',
'blue',
'brown',
'yellow'
);
Solution that works but I am not sure if it is the most efficient because the use of array_merge in a loop seems to be ugly:
$output = array();
foreach($example as $v) {
array_merge($output , $v);
}
Is there more efficient way of doing this?
</div>
One liner here is:
$output = call_user_func_array('array_merge', $example);
try this
$result = call_user_func_array('array_merge', $example);
print_r($result);
output will be
Edit As a text output
Array ( [0] => red [1] => green [2] => blue [3] => brown [4] => yellow )
Read more about call_user_func_array