在這個數組函數中我們想獲得酒店的詳細信息。我使用下面的代碼來獲取值。在那段代碼中我沒有得到正確的結果;一些酒店沒有顯示價格。 我也提供了輸出。多維數組獲取php中使用的值每個
Array
(
[TestMode] => true
[HotelAvailability] => Array
(
[0] => Array
(
[Hotel] => Array
(
[Id] => 87649
[Name] => Asmali
[Region] => Array
(
[Id] => 21303
[Name] => Old City
)
[Type] => Hotel
[Stars] => 3
[Rank] => 1
)
[Result] => Array
(
[0] => Array
(
[QuoteId] => 12297840-763
[Room] => Array
(
[RoomType] => Array
(
[Code] => 1103598
[Text] => Double Economy
)
[MealType] => Array
(
[Code] => 1000018
[Text] => Bed and breakfast
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 2094.87
[Estimated] => false
[Converted] => false
)
[Guests] => Array
(
[Adult] => Array
(
[0] => Array
(
[Id] => -452103032
[Forename] => Array
(
)
[Surname] => Array
(
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 1047.44
[Estimated] => false
[Converted] => false
)
)
[1] => Array
(
[Id] => -452103033
[Forename] => Array
(
)
[Surname] => Array
(
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 1047.43
[Estimated] => false
[Converted] => false
)
)
)
)
[Confirmation] => allocation
)
)
[1] => Array
(
[QuoteId] => 12297840-764
[Room] => Array
(
[RoomType] => Array
(
[Code] => 1002196
[Text] => Double Standard
)
[MealType] => Array
(
[Code] => 1000018
[Text] => Bed and breakfast
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 2993.22
[Estimated] => false
[Converted] => false
)
[Guests] => Array
(
[Adult] => Array
(
[0] => Array
(
[Id] => -452103034
[Forename] => Array
(
)
[Surname] => Array
(
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 1496.61
[Estimated] => false
[Converted] => false
)
)
[1] => Array
(
[Id] => -452103035
[Forename] => Array
(
)
[Surname] => Array
(
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 1496.61
[Estimated] => false
[Converted] => false
)
)
)
)
[Confirmation] => allocation
)
)
[2] => Array
(
[QuoteId] => 12297840-765
[Room] => Array
(
[RoomType] => Array
(
[Code] => 1002210
[Text] => Double Deluxe
)
[MealType] => Array
(
[Code] => 1000018
[Text] => Bed and breakfast
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 4190.37
[Estimated] => false
[Converted] => false
)
[Guests] => Array
(
[Adult] => Array
(
[0] => Array
(
[Id] => -452103036
[Forename] => Array
(
)
[Surname] => Array
(
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 2095.18
[Estimated] => false
[Converted] => false
)
)
[1] => Array
(
[Id] => -452103037
[Forename] => Array
(
)
[Surname] => Array
(
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 2095.19
[Estimated] => false
[Converted] => false
)
)
)
)
[Confirmation] => allocation
)
)
[3] => Array
(
[QuoteId] => 12297840-329
[Room] => Array
(
[RoomType] => Array
(
[Code] => 1286415
[Text] => Twin (Standard Twin)
)
[MealType] => Array
(
[Code] => 1000030
[Text] => Full Breakfast
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 5384.70
[Estimated] => false
[Converted] => false
)
[Guests] => Array
(
[Adult] => Array
(
[0] => Array
(
[Id] => -113025469
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 2692.35
[Estimated] => false
[Converted] => false
)
)
[1] => Array
(
[Id] => -113025470
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 2692.35
[Estimated] => false
[Converted] => false
)
)
)
)
[Confirmation] => allocation
)
)
[4] => Array
(
[QuoteId] => 12297840-348
[Room] => Array
(
[RoomType] => Array
(
[Code] => 1832194
[Text] => Double (Standard Twin)
)
[MealType] => Array
(
[Code] => 1000030
[Text] => Full Breakfast
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 5384.70
[Estimated] => false
[Converted] => false
)
[Guests] => Array
(
[Adult] => Array
(
[0] => Array
(
[Id] => -113025507
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 2692.35
[Estimated] => false
[Converted] => false
)
)
[1] => Array
(
[Id] => -113025508
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 2692.35
[Estimated] => false
[Converted] => false
)
)
)
)
[Confirmation] => allocation
)
)
)
)
[1] => Array
(
[Hotel] => Array
(
[Id] => 1712021
[Name] => May Hotel
[Region] => Array
(
[Id] => 21303
[Name] => Old City
)
[Type] => Hotel
[Stars] => 4
[Rank] => 1
)
[Result] => Array
(
[QuoteId] => 12297840-899
[Room] => Array
(
[RoomType] => Array
(
[Code] => 1002196
[Text] => Double Standard
)
[MealType] => Array
(
[Code] => 1000018
[Text] => Bed and breakfast
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 2217.18
[Estimated] => false
[Converted] => false
)
[Guests] => Array
(
[Adult] => Array
(
[0] => Array
(
[Id] => -452103440
[Forename] => Array
(
)
[Surname] => Array
(
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 1108.59
[Estimated] => false
[Converted] => false
)
)
[1] => Array
(
[Id] => -452103441
[Forename] => Array
(
)
[Surname] => Array
(
)
[SellingPrice] => Array
(
[Currency] => INR
[Amount] => 1108.59
[Estimated] => false
[Converted] => false
)
)
)
)
[Confirmation] => allocation
)
)
)
輸出:
87649 - Asmali: Old City 3
1712021 - May Hotel: Old City 4 INR 2217.18
我的代碼:
foreach($array_data['HotelAvailability'] as $hotel) {
$id = $hotel['Hotel']['Id'];
$name = $hotel['Hotel']['Name'];
$region = $hotel['Hotel']['Region']['Name'];
$stars = $hotel['Hotel']['Stars'];
$price = $hotel['Result']['Room']['SellingPrice']['Currency'] . ' ' . $hotel['Result']['Room']['SellingPrice']['Amount'] ;
echo "$id - $name: $region $stars $price<br>\n";
}
如果我使用此代碼,我m到處錯誤 - 致命錯誤:無法使用字符串作爲陣列偏移。顯示多個價格酒店,但如果只有一個房間類型只有一個價格酒店不顯示即時通訊錯誤。請解決這個問題 – Abiram
你試過我的第二個解決方案嗎?你需要把它放在你的第一個循環中 – Fabio
我只嘗試第二個選項。但我得到輸出。在此輸出中會顯示多個價格酒店。單價酒店沒有顯示,並得到一個錯誤 - 致命錯誤:不能使用字符串偏移量作爲一個數組 – Abiram