0

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]
                                                                )

                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

)

1 Answer 1

0

Follow this link solution :-

I think help this link.

THANKS.

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.