对象成员的Echo对象成员

时间:2015-02-13 12:28:33

标签: php arrays object

我在这里尝试做的是回应数组中的值,例如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

1 个答案:

答案 0 :(得分:1)

找到答案:

我将json_decode更改为true,因此我获得了数组。

然后我回应:

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