phparraysmultidimensional-arraymerging-data

Append rows from a 2d array to another 2d array


array_push($array, getData()) gives me:

Array
(
    [customer] => One
    [itemno] => Yellow Ribbon

)
Array
(
    [customer] => One
    [itemno] => Blue Band
)
Array
(
    [0] => Array
        (
            [customer] => Two
            [itemno] => Red Tape
        )
)

But what I want is:

Array
(
    [customer] => One
    [itemno] => Yellow Ribbon

)
Array
(
    [customer] => One
    [itemno] => Blue Band
)
Array
(
    [customer] => Two
    [itemno] => Red Tape
)

What am I supposed to use?


Solution

  • Assuming you're using numeric keys in $array, a simple array_merge($array,getData()) should work, because getData() apparently returns a numeric-indexed multi-dimensional array.