flowplayer
flowplayer

Reputation: 13

push an array into another array

I have one two function, those are return array. Now using my first function :

$output = array(
    'status' => $status,
    'message' => $message,
    'result' => shopping_list()
);

Here shopping_list() is my first function.

Now If i print $output as JSON then result shown

{
    "status":"0",
    "message":"Already In List",
    "result":[
        {
            "id":"4",
            "name":"sazib",
            "status":"main",
            "item_list":[
                {
                    "id":"4",
                    "name":"item1",
                    "picture":"",
                    "purchase_status":"yes",
                    "total_quantity":"4"
                }
            ]
        }
        ]

}

I have another function that also return an array.

Example:

Array
(
    [0] => Array
        (
            [id] => 
            [name] => sazib
            [list_status] => sync
            [item_list] => Array
                (
                    [0] => Array
                        (
                            [id] => 10
                            [name] => test
                            [picture] => 
                            [purchase_status] => no
                            [total_quantity] => 3
                        )

                    [1] => Array
                        (
                            [id] => 11
                            [name] => prime
                            [picture] => 
                            [purchase_status] => no
                            [total_quantity] => 1
                        )

                )

        )

)

My second function Sync_shopping_list() return array.

Now I have need to add my second function data into $output result array ( "result": ).

I am trying to push it before printing.

array_push($output->result,Sync_shopping_list());

But not work

Upvotes: 1

Views: 63

Answers (1)

xdazz
xdazz

Reputation: 160833

Use array_merge:

$output = array(
    'status' => $status,
    'message' => $message,
    'result' => array_merge(shopping_list(), Sync_shopping_list())
);

Or add it later by:

$output['result'] = array_merge($output['result'], Sync_shopping_list());

Upvotes: 1

Related Questions