I have the following array which gets populated with database values (except for 'PickItems' in this example):
$params = array(
'DeliveryCompanyName' => $row['company_name'],
'DeliveryAddress1' => $row['address1'],
'DeliveryAddress2' => $row['address2'],
'DeliveryCity' => $row['city'],
'DeliveryCounty' => $row['province'],
'DeliveryPostCode' => $row['postcode'],
'DeliveryCountry' => $row['country'],
'DeliveryPhone' => $row['phone'],
'DeliveryContact' => $row['first_name'] . " " . $row['last_name'],
'OutboundRef' => $row['order_number'],
'PickItems' => array(
array(
'SKUNumber' => 'SKU',
'Quantity' => '1',
'Comments' => 'Comments'
)
),
'BranchID' => '',
'CustRef' => $row['order_number']
);
Within this array, is an item called "PickItems" which contains an array of array's which are each seperate products ordered.
I am trying to wrap my head around using a while loop on another database query to populate these "PickItems".
Here is the code which I started off writing in order to loop through the database that contains the individual items for the order, and I need to put these into an array and put that array into the main array. The part I am struggling with is putting these values and keys into the array, I thought array_push was the way to go but another answer on another question says you can't do this.
if ($result2 = $mysqli->query("SELECT * FROM order_items WHERE client_id = {$client} AND main_order_id = {$row['platform_order_id']}")) {
$Items = array();
while($row2 = mysqli_fetch_assoc($result2)) {
//Add the following values to the items array
//'SKUNumber' => $row2['sku'],
//'Quantity' => $row2['quantity'],
//'Comments' => $row2['comments']
}
}
I suspect that the main array needs to change to something like this? :
$params = array(
'DeliveryCompanyName' => $row['company_name'],
'DeliveryAddress1' => $row['address1'],
'DeliveryAddress2' => $row['address2'],
'DeliveryCity' => $row['city'],
'DeliveryCounty' => $row['province'],
'DeliveryPostCode' => $row['postcode'],
'DeliveryCountry' => $row['country'],
'DeliveryPhone' => $row['phone'],
'DeliveryContact' => $row['first_name'] . " " . $row['last_name'],
'OutboundRef' => $row['order_number'],
'PickItems' => array($Items),
'BranchID' => '',
'CustRef' => $row['order_number']
);