Peter Omiyi Peter Omiyi - 2 months ago 27
PHP Question

Shopify orders array issue

I have these two arrays

$order2 = array('line_items' => array(
array('title' => 'Shipping',
'price' => '10',
'quantity' => '2',
)
));

$order3 =array('title' => 'Handling',
'price' => '5',
'quantity' => '1',
);


I've used array_merge and array_push in this instance but both don't give me my desired output. I'm trying to get it to show like this.

array('line_items' => array(
array('title' => 'Shipping',
'price' => '10',
'quantity' => '2',
),
array('title' => 'Handling',
'price' => '5',
'quantity' => '1',
)
));


The output i get is

Array ( [line_items] => Array ( [0] => Array ( [title] => Shipping [price] => 10 [quantity] => 2 ) ) [title] => Handling [price] => 5 [quantity] => 1 )


How can i achieve my desired output so i can use this as a shopify order?

Answer

You don't need any functions to do that, just a simple array assignment on top of the existing one:

$order2['line_items'][] = $order3;