0

I am trying to track shipments from the Aramex API. The following result is the response I got from the request sent to track shipment number 59398114932:

stdClass Object
(
    [Transaction] => stdClass Object
        (
            [Reference1] => 
            [Reference2] => 
            [Reference3] => 
            [Reference4] => 
            [Reference5] => 
        )

    [Notifications] => stdClass Object
        (
        )

    [HasErrors] => 
    [TrackingResults] => stdClass Object
        (
            [KeyValueOfstringArrayOfTrackingResultmFAkxlpY] => stdClass Object
                (
                    [Key] => 59398114932
                    [Value] => stdClass Object
                        (
                            [TrackingResult] => stdClass Object
                                (
                                    [WaybillNumber] => 59398114932
                                    [UpdateCode] => SH005
                                    [UpdateDescription] => Delivered
                                    [UpdateDateTime] => 2016-09-26T14:45:00
                                    [UpdateLocation] => new york
                                    [Comments] => joe
                                    [ProblemCode] => 
                                )
                        )
                )
        )
)

But what I actually need is only the [UpdateDescription] from the above response in order to know when the shipment is delivered. How can I echo it?

Here is the request I sent:

$auth_call = $soapClient->TrackShipments($params);

The shipment number is sent by the $params array.

honk
  • 9,137
  • 11
  • 75
  • 83
codehelp
  • 23
  • 4

2 Answers2

0

Because you have the array of Object, you need to use -> for each depth of the array. Let your response array object is $response.

echo $response->TrackingResults->KeyValueOfstringArrayOfTrackingR‌​esultmFAkxlpY->Value‌​->TrackingResult->Up‌​dateDescription;

There is nothing complex, just simple. Use the -> sign for the each array depth of this array object.

Murad Hasan
  • 9,565
  • 2
  • 21
  • 42
0

If you only need the Update Description, then this should do it:

echo $your_object->TrackingResults->KeyValueOfstringArrayOfTrackingResultmFAkxlpY->Value->TrackingResult->UpdateDescription;
Rax Weber
  • 3,730
  • 19
  • 30
  • no output from echoing – codehelp Sep 28 '16 at 09:39
  • Have you replaced $your_object to the real name of the response object? – Rax Weber Sep 28 '16 at 09:45
  • yes replaced it with $auth_call – codehelp Sep 28 '16 at 09:52
  • how did you print the response that you have shown above? – Rax Weber Sep 28 '16 at 10:05
  • $auth_call = $soapClient->TrackShipments($params); print_r($soapClient->TrackShipments($params)); echo $auth_call->TrackingResults->KeyValueOfstringArrayOfTracking‌​ResultmFAkxlpY->Valu‌​e->TrackingResult->U‌​pdateDescription; – codehelp Sep 28 '16 at 10:10
  • any thing i need to change ? – codehelp Sep 28 '16 at 10:46
  • Hmmm. Can you store in a variable and use print_r to print? Like this: $auth_call = $soapClient->TrackShipments($params); print_r($soapClient->TrackShipments($params)); $update_description = $auth_call->TrackingResults->KeyValueOfstringArrayOfTracking‌​‌​ResultmFAkxlpY->Va‌​lu‌​e->TrackingResul‌​t; (Note: Only until TrackingResult so that we can check its structure and content) – Rax Weber Sep 28 '16 at 14:43