Stfvns Stfvns - 1 month ago 14
PHP Question

Merge array inside array

I have 2 array to merge. first array is multidimentional, and second array is single array:

$a = array(
array('id'=>'1', 'name'=>'Mike'),
array('id'=>'2', 'name'=>'Lina'),
);

$b = array('id'=>'3', 'name'=>'Niken');


How to merge 2 array have same array deep?

Answer

If what you want is this:

array(
    array('id'=>'1', 'name'=>'Mike'),
    array('id'=>'2', 'name'=>'Lina'),
    array('id'=>'3', 'name'=>'Niken')
)

You can just add the second as a new element to the first:

$one[] = $two;
Comments