Salman Riyaz
Salman Riyaz

Reputation: 818

how to display an array converted from xml

I have an Array which i got after converting from an XML, This XML is coming from amazon seller account. It has got all the orders which are available in my seller account.

Im using Yii 2.0 php framework, Im passing this array to view after converting from XML to array in controller. This is my array..

Array
    (
        [ListOrdersResult] => Array
            (
                [CreatedBefore] => 2016-07-11T05:59:05Z
                [Orders] => Array
                    (
                        [Order] => Array
                            (
                                [0] => Array
                                    (
                                        [AmazonOrderId] => 171-4557760-7388350
                                        [PurchaseDate] => 2016-06-01T13:07:46Z
                                        [LastUpdateDate] => 2016-06-03T12:43:26Z
                                        [OrderStatus] => Canceled
                                        [FulfillmentChannel] => MFN
                                        [SalesChannel] => Amazon.in
                                        [ShipServiceLevel] => IN Exp Dom 2
                                        [OrderTotal] => Array
                                            (
                                                [CurrencyCode] => INR
                                                [Amount] => 40.00
                                            )

                                        [NumberOfItemsShipped] => 0
                                        [NumberOfItemsUnshipped] => 0
                                        [PaymentExecutionDetail] => Array
                                            (
                                            )

                                        [MarketplaceId] => A21TJRUUN4KGV
                                        [ShipmentServiceLevelCategory] => Expedited
                                        [ShippedByAmazonTFM] => false
                                        [OrderType] => StandardOrder
                                        [EarliestShipDate] => 2016-06-01T18:30:00Z
                                        [LatestShipDate] => 2016-06-03T18:29:59Z
                                        [IsPrime] => false
                                        [IsPremiumOrder] => false
                                    )

                                [1] => Array
                                    (
                                        [AmazonOrderId] => 403-4718683-0373128
                                        [PurchaseDate] => 2016-06-03T12:30:20Z
                                        [LastUpdateDate] => 2016-06-03T14:02:13Z
                                        [OrderStatus] => Canceled
                                        [FulfillmentChannel] => MFN
                                        [SalesChannel] => Amazon.in
                                        [ShipServiceLevel] => IN Exp Dom 2
                                        [OrderTotal] => Array
                                            (
                                                [CurrencyCode] => INR
                                                [Amount] => 40.00
                                            )

                                        [NumberOfItemsShipped] => 0
                                        [NumberOfItemsUnshipped] => 0
                                        [PaymentExecutionDetail] => Array
                                            (
                                            )

                                        [MarketplaceId] => A21TJRUUN4KGV
                                        [ShipmentServiceLevelCategory] => Expedited
                                        [ShippedByAmazonTFM] => false
                                        [OrderType] => StandardOrder
                                        [EarliestShipDate] => 2016-06-03T18:30:00Z
                                        [LatestShipDate] => 2016-06-06T18:29:59Z
                                        [IsPrime] => false
                                        [IsPremiumOrder] => false
                                    )


                            )

                    )

            )

        [ResponseMetadata] => Array
            (
                [RequestId] => 42c3353b-d6af-459f-9421-5e8b7efb8ea8
            )

    )

Here each array is am order, Now i want to display one by one.. can anyone kindly help me how to i display.. Im using Yii2 Php framework for this project... Thank you..

Upvotes: 1

Views: 87

Answers (1)

fantaghirocco
fantaghirocco

Reputation: 4878

It should be something like this:

$myArray['ListOrdersResult']['Orders']['Order'][0]['AmazonOrderId'] = '171-4557760-7388350';

function print_order($order) {
    foreach ($order as $key1=>$val) {
        if (is_array($val))
            print_order($val);
        else
            print "$key1  = $val<br/>\r\n";
    }
}

print_order($myArray['ListOrdersResult']['Orders']['Order']);

Upvotes: 1

Related Questions