1

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

1 Answer 1

1

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());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.