来自货件跟踪响应的 stdClass 对象的回显项目

Echo item from stdClass object from shipment tracking response

我正在尝试跟踪来自 Aramex API 的货物。以下结果是我从发送跟踪货件号 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] => 
                                )
                        )
                )
        )
)

但我真正需要的只是上述回复中的[UpdateDescription],以便知道货物何时送达。我怎样才能回应它?

这是我发送的请求:

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

货件号由$params数组发送。

因为你有Object的数组,所以需要对数组的每个深度使用->。让你的响应数组对象是$response.

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

没有什么复杂的,只有简单的。使用 -> 符号表示此数组对象的每个数组深度。

如果您只需要更新说明,那么应该这样做:

echo $your_object->TrackingResults->KeyValueOfstringArrayOfTrackingResultmFAkxlpY->Value->TrackingResult->UpdateDescription;