How to merge array in one array under foreach loop

I have array i want to merge under foreach loop please provide sollution how can i do it.

Array
(
    [0] => Array
        (
            [id] => 377556
            [name] => 8 Ball Pool iOS App - US *
	)
)

Array
(
    [0] => Array
        (
            [id] => 377555
            [name] => test data
	)
)

i want below result so please provide sollution how can i merge data in one array .
Thanks in advance

Array
(
    [0] => Array
        (
            [id] => 377556
            [name] => 8 Ball Pool iOS App - US *
	)
    [1] => Array
        (
            [id] => 377555
            [name] => test data
	)
)

http://php.net/array-merge

i have already try this function but my array is under foreach loop so its not working for me

then you need to provide more information. because what an ‘array is under foreach loop’ nobody of us can tell.

This is the sollution of my question.

$result=[];
foreach($main_array as $array){
    $result = array_merge($result, $array);
}
print_r($result);

there’s an easier way to do that:

$result = array_reduce($main_array, 'array_merge', []);
2 Likes

thanks for sollution

it’s solution with a single l

1 Like

yes its true

it’s … without the apostrophe it means the possesive

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.