Dominik
Dominik

Reputation: 4768

PHP array_push not the right function, what to use?

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?

Upvotes: 1

Views: 155

Answers (2)

Chris
Chris

Reputation: 12078

This will do what you want...

$array[] = getData(); 

Upvotes: 0

bcosca
bcosca

Reputation: 17555

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.

Upvotes: 1

Related Questions