What I'm trying to achieve is to build the array that should match exactly the structure of an Json decoded version. I am stuck where I need to address indexed array within an array. It would be a great help if someone could help me cross where I'm stuck.
// Array to be built to match JSON decoded version of associative array.
$fulfillment_array['orderShipment']['orderLines']['orderLine'] = [];
foreach ($fulfillment_records as $this_fulfillment_record) {
// Assemble the fulfillment array for Walmart.
$fulfillment_array['orderShipment']['orderLines']['orderLine'][] = array(
"lineNumber" =>
"sellerOrderId" =>
"orderLineStatuses" => array(
"orderLineStatus" => array (
// Is this the right way of addressing an indexed array to match the structure of associative array below.
array (
"status" => "Shipped",
"statusQuantity" => array(
"unitOfMeasurement" => "Each",
"amount" =>
)
)
)
)
);
The Associative array that I am trying to build with my code above is
Array
(
[orderShipment] => Array
(
[orderLines] => Array
(
[orderLine] => Array
(
[0] => Array
(
[lineNumber] => 1
[sellerOrderId] => 92344
[orderLineStatuses] => Array
(
[orderLineStatus] => Array
(
[0] => Array
(
[status] => Shipped
[statusQuantity] => Array
(
[unitOfMeasurement] => EACH
[amount] => 1
)
[trackingInfo] => Array
(
[shipDateTime] => 1580821866000
[carrierName] => Array
(
[otherCarrier] =>
[carrier] => UPS
)
[methodCode] => Standard
[trackingNumber] => 22344
[trackingURL] => http://walmart/tracking/ups?&type=MP&seller_id=12345&promise_date=03/02/2020&dzip=92840&tracking_numbers=92345
)
[returnCenterAddress] => Array
(
[name] => walmart
[address1] => walmart store 2
[address2] =>
[city] => Huntsville
[state] => AL
[postalCode] => 35805
[country] => USA
[dayPhone] => 12344
[emailId] => [email protected]
)
)
)
)
)
[1] => Array
(
[lineNumber] => 2
[sellerOrderId] => 92344
[orderLineStatuses] => Array
(
[orderLineStatus] => Array
(
[0] => Array
(
[status] => Shipped
[statusQuantity] => Array
(
[unitOfMeasurement] => EACH
[amount] => 1
)
[trackingInfo] => Array
(
[shipDateTime] => 1580821866000
[carrierName] => Array
(
[otherCarrier] =>
[carrier] => FedEx
)
[methodCode] => Express
[trackingNumber] => 22344
[trackingURL] => http://walmart/tracking/fedEx?&type=MP&seller_id=12345&promise_date=03/02/2020&dzip=92840&tracking_numbers=92344
)
[returnCenterAddress] => Array
(
[name] => walmart
[address1] => walmart store 2
[address2] =>
[city] => Huntsville
[state] => AL
[postalCode] => 35805
[country] => USA
[dayPhone] => 12344
[emailId] => [email protected]
)
)
)
)
)
)
)
)
)
asked Jul 27, 2020 at 10:05
CodeForGood
7649 silver badges44 bronze badges
1 Answer 1
Follow this link solution :-
I think help this link.
THANKS.
answered Aug 15, 2020 at 11:16
Mohit Patel
4,0484 gold badges27 silver badges57 bronze badges
default