0

I need to access the value of certain keys that are returned from an ebay xml request. When the xml is parsed I'm using the following code to make a Json array out of it and display it in the page.

$xml = simplexml_load_string($eBayResponse, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

echo '<pre>'; print_r($array); echo '</pre>';

The result looks similar to this (I wont print it all here)...

Array
(
    [Timestamp] => 2022-02-07T15:56:53.324Z
    [Ack] => Success
    [Version] => 1241
    [Build] => E1241_CORE_APIXO_19220561_R1
    [PaginationResult] => Array
        (
            [TotalNumberOfPages] => 1
            [TotalNumberOfEntries] => 2
        )

    [HasMoreOrders] => false
    [OrderArray] => Array
        (
            [Order] => Array
                (
                    [0] => Array
                        (
                            [OrderID] => 01-08113-51114
                            [OrderStatus] => Completed
                            [AdjustmentAmount] => 0.0
                            [AmountPaid] => 11.24
                            [AmountSaved] => 0.0
                            [CheckoutStatus] => Array
                                (
                                    [eBayPaymentStatus] => NoPaymentFailure
                                    [LastModifiedTime] => 2022-02-07T01:49:06.000Z
                                    [PaymentMethod] => CreditCard
                                    [Status] => Complete
                                    [IntegratedMerchantCreditCardEnabled] => true
                                    [PaymentInstrument] => PayPal
                                )

                            [ShippingDetails] => Array
                                (
                                    [SalesTax] => Array
                                        (
                                            [SalesTaxPercent] => 0.0
                                            [SalesTaxState] => Array
                                                (
                                                )

                                            [ShippingIncludedInTax] => false
                                            [SalesTaxAmount] => 0.0
                                        )

So now I want to echo the value for the key [OrderID] in PHP. It should be really simple but I cant get the result. I tried things like...

echo $array['0']['OrderID'];

But don't get anything echoed out to the page. I need to grab the value of keys at each array assuming its like a directory that you need a path to?

echo $array['Array'][0][CheckoutStatus][PaymentMethod];

There are tons of posts about formatting and printing a readable result of an array structure but not how to obtain the value for a specific key.

All tips gratefully received!

tard
  • 1
  • 1

0 Answers0