回显对象成员的对象成员

Echo object member of object member

我在这里要做的是呼出数组中的值,例如 NAME

到目前为止我能做的就是回显顶层的值,例如

foreach ($response as $key => $value) {
echo $value->customerSessionId;

给我正确的输出:0ABAAAD2-6922-6914-B822-E2C2A4906CC5

但我想从 HotelSummary 下的数组中回显 - 我该怎么做?

结构如下:

stdClass Object
(
[HotelListResponse] => stdClass Object
    (
        [customerSessionId] => 0ABAAAD2-6922-6914-B822-E2C2A4906CC5
        [numberOfRoomsRequested] => 1
        [moreResultsAvailable] => 1
        [cacheKey] => -16869226:14b82e2c2a4:-6cc3
        [cacheLocation] => 10.186.170.210:7300
        [cachedSupplierResponse] => stdClass Object
            (
                [@supplierCacheTolerance] => MED_ENHANCED
                [@cachedTime] => 0
                [@cacheEntryMissNum] => 88
                [@cacheRetrievalTime] => 1
                [@supplierRequestNum] => 88
                [@supplierResponseNum] => 20
                [@supplierResponseTime] => 162
                [@candidatePreptime] => 40
                [@otherOverheadTime] => 9
                [@tpidUsed] => 5100
                [@matchedCurrency] => true
                [@extrapolatedLocale] => true
            )

        [HotelList] => stdClass Object
            (
                [@size] => 20
                [@activePropertyCount] => 88
                [HotelSummary] => Array
                    (
                        [0] => stdClass Object
                            (
                                [@order] => 0
                                [@ubsScore] => 321327565
                                [hotelId] => 168016
                                [name] => First Hotel Mayfair
                                [address1] => Helgolandsgade 3
                                [city] => Copenhagen
                                [postalCode] => 1653
                                [countryCode] => DK
                                [airportCode] => CPH
                                [supplierType] => E
                                [propertyCategory] => 1

找到答案:

我将 json_decode 更改为 true 所以我得到了数组。

然后我回应:

echo $value['HotelList']['HotelSummary'][0][name];