How can i echo each hotelCode, totalPrice, boardType and roomCategory from the below multidimmensional array
<?php
$hotelCodes = array() ;
$availHotels = $checkAvailability->availableHotels ;
foreach($availHotels as $hotel){
if (!isset($hotelCodes[$hotel->hotelCode])) {
$hotelCodes[$hotel->hotelCode] = array();
}
// you could ofcourse just take specific info from $hotel and put it in here.
$hotelCodes[$hotel->hotelCode][] = $hotel;
}
?>
and
print_r of $hotelCodes is
Array ( [HOTELCODE1] => Array ( [0] => stdClass Object ( [processId] => HV-82768336 [hotelCode] => ITULJP [availabilityStatus] => InstantConfirmation [totalPrice] => 279 [totalTax] => 0 [totalSalePrice] => 298.86 [currency] => EUR [boardType] => Breakfast Buffet [rooms] => Array ( [0] => stdClass Object ( [roomCategory] => Twin Room - Non-Refundable-1 double bed [paxes] => Array ( [0] => stdClass Object ( [paxType] => Adult [age] => 30 ) [1] => stdClass Object ( [paxType] => Adult [age] => 30 ) ) [totalRoomRate] => 279 [ratesPerNight] => Array ( [0] => stdClass Object ( [date] => 2015-03-11 [amount] => 34.84 ) [1] => stdClass Object ( [date] => 2015-03-12 [amount] => 34.88 ) [2] => stdClass Object ( [date] => 2015-03-13 [amount] => 34.88 ) [3] => stdClass Object ( [date] => 2015-03-14 [amount] => 34.88 ) [4] => stdClass Object ( [date] => 2015-03-15 [amount] => 34.88 ) [5] => stdClass Object ( [date] => 2015-03-16 [amount] => 34.88 ) [6] => stdClass Object ( [date] => 2015-03-17 [amount] => 34.88 ) [7] => stdClass Object ( [date] => 2015-03-18 [amount] => 34.88 ) ) ) ) ) [1] => stdClass Object ( [processId] => HN-10616086 [hotelCode] => ITULJP [availabilityStatus] => InstantConfirmation [totalPrice] => 294 [totalTax] => 0 [totalSalePrice] => 314.59 [currency] => EUR [boardType] => Breakfast Buffet [rooms] => Array ( [0] => stdClass Object ( [roomCategory] => Double or Twin Room-1 double bed [paxes] => Array ( [0] => stdClass Object ( [paxType] => Adult [age] => 30 ) [1] => stdClass Object ( [paxType] => Adult [age] => 30 ) ) [totalRoomRate] => 294 [ratesPerNight] => Array ( [0] => stdClass Object ( [date] => 2015-03-11 [amount] => 36.75 ) [1] => stdClass Object ( [date] => 2015-03-12 [amount] => 36.75 ) [2] => stdClass Object ( [date] => 2015-03-13 [amount] => 36.75 ) [3] => stdClass Object ( [date] => 2015-03-14 [amount] => 36.75 ) [4] => stdClass Object ( [date] => 2015-03-15 [amount] => 36.75 ) [5] => stdClass Object ( [date] => 2015-03-16 [amount] => 36.75 ) [6] => stdClass Object ( [date] => 2015-03-17 [amount] => 36.75 ) [7] => stdClass Object ( [date] => 2015-03-18 [amount] => 36.75 ) ) ) ) ) ) [HOTELCODE2] => Array ( [0] => stdClass Object ( [processId] => HZ-21733446 [hotelCode] => ITOI6P [availabilityStatus] => InstantConfirmation [totalPrice] => 295 [totalTax] => 0 [totalSalePrice] => 0 [currency] => EUR [boardType] => Room Only [rooms] => Array ( [0] => stdClass Object ( [roomCategory] => Double Or Twin Standard [paxes] => Array ( [0] => stdClass Object ( [paxType] => Adult [age] => 30 ) [1] => stdClass Object ( [paxType] => Adult [age] => 30 ) ) [totalRoomRate] => 295 [ratesPerNight] => Array ( [0] => stdClass Object ( [date] => 2015-03-11 [amount] => 37 ) [1] => stdClass Object ( [date] => 2015-03-12 [amount] => 37 ) [2] => stdClass Object ( [date] => 2015-03-13 [amount] => 37 ) [3] => stdClass Object ( [date] => 2015-03-14 [amount] => 37 ) [4] => stdClass Object ( [date] => 2015-03-15 [amount] => 37 ) [5] => stdClass Object ( [date] => 2015-03-16 [amount] => 37 ) [6] => stdClass Object ( [date] => 2015-03-17 [amount] => 37 ) [7] => stdClass Object ( [date] => 2015-03-18 [amount] => 36 ) ) ) ) ) ) )
I need to echo the values
HOTELCODE1 and HOTELCODE1 as $hotelcode[1] and $hotelcode[2]
and totalRoomRate, roomCategory and boardType for each hotelcode
Thanks
You're already there, you just need to make sure only one hotel is stored for any hotel-code.
foreach($availHotels as $hotel){
// if we do not have a hotel with this code yet
if (!isset($hotelCodes[$hotel->hotelCode])) {
// store this one there
$hotelCodes[$hotel->hotelCode] = $hotel;
}
}
// run over the available hotels
foreach( $hotelCodes as $hotel ) {
echo $hotel['hotelCode'] . ' -> ' . $hotel['totalPrice' ] . ' -> etc ';
}
Related
I'm just on the hose and dont get on.
I am not a professional programmer but have so far with much reading and over numerous attempts everything so far created what I have undertaken, only with this I have probably found my masterpiece.
I have a response of a SOAP query and would like to display the values in a table for each powerUnitidentifier. What is the best way to do this?
(
[RawData] => stdClass Object
(
[from] => 2022-05-10T01:00:00+02:00
[to] => 2022-05-10T01:20:00+02:00
[dataRecords] => stdClass Object
(
[record] => Array
(
[0] => stdClass Object
(
[powerUnitIdentifier] => abc123
[time] => 2022-05-10T01:00:00+02:00
[fields] => stdClass Object
(
[field] => Array
(
[0] => stdClass Object
(
[identifier] => 100
[value] => 0
)
[1] => stdClass Object
(
[identifier] => 101
[value] => 3.27
)
[2] => stdClass Object
(
[identifier] => 102
[value] => 70.00
)
)
)
)
[1] => stdClass Object
(
[powerUnitIdentifier] => zyx321
[time] => 2022-05-10T01:00:00+02:00
[fields] => stdClass Object
(
[field] => Array
(
[0] => stdClass Object
(
[identifier] => 100
[value] => 0
)
[1] => stdClass Object
(
[identifier] => 101
[value] => 3.19
)
[2] => stdClass Object
(
[identifier] => 102
[value] => 70.00
)
)
)
)
[2] => stdClass Object
(
[powerUnitIdentifier] => abc123
[time] => 2022-05-10T01:10:00+02:00
[fields] => stdClass Object
(
[field] => Array
(
[0] => stdClass Object
(
[identifier] => 100
[value] => 0
)
[1] => stdClass Object
(
[identifier] => 101
[value] => 3.15
)
[2] => stdClass Object
(
[identifier] => 102
[value] => 70.00
)
)
)
)
[3] => stdClass Object
(
[powerUnitIdentifier] => zyx321
[time] => 2022-05-10T01:10:00+02:00
[fields] => stdClass Object
(
[field] => Array
(
[0] => stdClass Object
(
[identifier] => 100
[value] => 0
)
[1] => stdClass Object
(
[identifier] => 101
[value] => 3.09
)
[2] => stdClass Object
(
[identifier] => 102
[value] => 70.00
)
)
)
)
)
)
)
)```
You loop over the section of the data, starting the foreach loop at the right level of your data structure
foreach($theName->RawData->DataRecords->record as $obj) {
echo $obj->powerUnitIdentifier;
}
Or if you ment to process the sub array of that
foreach($theName->RawData->DataRecords->record as $obj) {
echo $obj->powerUnitIdentifier . '<br>';
foreach( $obj->fields as $field) {
echo $field->identifier . ',' . $field->value . '<br>';
}
}
I want to implement pagination using "Flight Offers Search" of Amadeus API. There is no parameter to passing limit and offset using "Flight Offers Search" of Amadeus API.
I have bellow API URL with filter parameter to get flight list
https://api.amadeus.com/v2/shopping/flight-offers?originLocationCode=JFK&destinationLocationCode=LHR&departureDate=2021-09-02&returnDate=2021-09-05&adults=1&travelClass=ECONOMY¤cyCode=USD&max=10
And I got response from API like this
stdClass Object
(
[meta] => stdClass Object
(
[count] => 10
[links] => stdClass Object
(
[self] => https://api.amadeus.com/v2/shopping/flight-offers?originLocationCode=JFK&destinationLocationCode=LHR&departureDate=2021-09-02&returnDate=2021-09-05&adults=1&travelClass=ECONOMY¤cyCode=USD&max=10
)
)
[data] => Array
(
[0] => stdClass Object
(
[type] => flight-offer
[id] => 1
[source] => GDS
[instantTicketingRequired] =>
[nonHomogeneous] =>
[oneWay] =>
[lastTicketingDate] => 2021-08-28
[numberOfBookableSeats] => 9
[itineraries] => Array
(
[0] => stdClass Object
(
[duration] => PT6H50M
[segments] => Array
(
[0] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => JFK
[terminal] => 4
[at] => 2021-09-02T08:15:00
)
[arrival] => stdClass Object
(
[iataCode] => LHR
[terminal] => 3
[at] => 2021-09-02T20:05:00
)
[carrierCode] => VS
[number] => 26
[aircraft] => stdClass Object
(
[code] => 789
)
[operating] => stdClass Object
(
[carrierCode] => VS
)
[duration] => PT6H50M
[id] => 3
[numberOfStops] => 0
[blacklistedInEU] =>
)
)
)
[1] => stdClass Object
(
[duration] => PT8H15M
[segments] => Array
(
[0] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => LHR
[terminal] => 3
[at] => 2021-09-05T10:10:00
)
[arrival] => stdClass Object
(
[iataCode] => JFK
[terminal] => 4
[at] => 2021-09-05T13:25:00
)
[carrierCode] => VS
[number] => 4007
[aircraft] => stdClass Object
(
[code] => 764
)
[operating] => stdClass Object
(
[carrierCode] => DL
)
[duration] => PT8H15M
[id] => 8
[numberOfStops] => 0
[blacklistedInEU] =>
)
)
)
)
[price] => stdClass Object
(
[currency] => USD
[total] => 709.86
[base] => 122.00
[fees] => Array
(
[0] => stdClass Object
(
[amount] => 0.00
[type] => SUPPLIER
)
[1] => stdClass Object
(
[amount] => 0.00
[type] => TICKETING
)
)
[grandTotal] => 709.86
)
[pricingOptions] => stdClass Object
(
[fareType] => Array
(
[0] => PUBLISHED
)
[includedCheckedBagsOnly] =>
)
[validatingAirlineCodes] => Array
(
[0] => VS
)
[travelerPricings] => Array
(
[0] => stdClass Object
(
[travelerId] => 1
[fareOption] => STANDARD
[travelerType] => ADULT
[price] => stdClass Object
(
[currency] => USD
[total] => 709.86
[base] => 122.00
)
[fareDetailsBySegment] => Array
(
[0] => stdClass Object
(
[segmentId] => 3
[cabin] => ECONOMY
[fareBasis] => NH3X36B1
[brandedFare] => LIGHT
[class] => T
[includedCheckedBags] => stdClass Object
(
[quantity] => 0
)
)
[1] => stdClass Object
(
[segmentId] => 8
[cabin] => ECONOMY
[fareBasis] => NH3X36B1
[brandedFare] => LIGHT
[class] => T
[includedCheckedBags] => stdClass Object
(
[quantity] => 0
)
)
)
)
)
)
)
[dictionaries] => stdClass Object
(
[locations] => stdClass Object
(
[LHR] => stdClass Object
(
[cityCode] => LON
[countryCode] => GB
)
[JFK] => stdClass Object
(
[cityCode] => NYC
[countryCode] => US
)
)
[aircraft] => stdClass Object
(
[772] => BOEING 777-200/200ER
[764] => BOEING 767-400
[77W] => BOEING 777-300ER
[777] => BOEING 777-200/300
[789] => BOEING 787-9
)
[currencies] => stdClass Object
(
[USD] => US DOLLAR
)
[carriers] => stdClass Object
(
[AA] => AMERICAN AIRLINES
[KL] => KLM ROYAL DUTCH AIRLINES
[AF] => AIR FRANCE
[DL] => DELTA AIR LINES
[AY] => FINNAIR
[VS] => VIRGIN ATLANTIC
[BA] => BRITISH AIRWAYS
)
)
)
There is no limit and offset parameter in this API.
Please guide me how to implement pagination using "Flight Offers Search" of Amadeus API.
Thank You
The Flight Offers Search API doesn't support pagination, that's why there are not parameters available to pass the limit and offset in the API reference. Checkout the pagination guide for more information.
I want to show flight's logo images in a flight list using flight offer price API:
https://developers.amadeus.com/self-service/category/air/api-doc/flight-offers-search/api-reference.
I search for flights using origin and destination, one way or round trip, etc. But the flight logo image is not available in the result. Is there a way I can get the flight logo image using the "flight-offers-search" API?
I have used bellow API URL to get flight offer price
This is my request URL
https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAN&destinationLocationCode=LAX&departureDate=2021-07-29&adults=1&travelClass=ECONOMY¤cyCode=USD&max=100
This is my API response. there is no flight logo image available in the response.
stdClass Object
(
[meta] => stdClass Object
(
[count] => 93
[links] => stdClass Object
(
[self] => https://test.api.amadeus.com/v2/shopping/flight-offers?originLocationCode=MAN&destinationLocationCode=LAX&departureDate=2021-07-29&adults=1&travelClass=ECONOMY¤cyCode=USD&max=100
)
)
[data] => Array
(
[0] => stdClass Object
(
[type] => flight-offer
[id] => 1
[source] => GDS
[instantTicketingRequired] =>
[nonHomogeneous] =>
[oneWay] =>
[lastTicketingDate] => 2021-07-29
[numberOfBookableSeats] => 4
[itineraries] => Array
(
[0] => stdClass Object
(
[duration] => PT29H42M
[segments] => Array
(
[0] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => MAN
[terminal] => 1
[at] => 2021-07-29T10:40:00
)
[arrival] => stdClass Object
(
[iataCode] => LIS
[terminal] => 1
[at] => 2021-07-29T13:30:00
)
[carrierCode] => TP
[number] => 1317
[aircraft] => stdClass Object
(
[code] => 32N
)
[operating] => stdClass Object
(
[carrierCode] => TP
)
[duration] => PT2H50M
[id] => 152
[numberOfStops] => 0
[blacklistedInEU] =>
)
[1] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => LIS
[terminal] => 1
[at] => 2021-07-29T18:30:00
)
[arrival] => stdClass Object
(
[iataCode] => EWR
[terminal] => B
[at] => 2021-07-29T21:30:00
)
[carrierCode] => TP
[number] => 207
[aircraft] => stdClass Object
(
[code] => 32Q
)
[operating] => stdClass Object
(
[carrierCode] => TP
)
[duration] => PT8H
[id] => 153
[numberOfStops] => 0
[blacklistedInEU] =>
)
[2] => stdClass Object
(
[departure] => stdClass Object
(
[iataCode] => JFK
[terminal] => 5
[at] => 2021-07-30T05:30:00
)
[arrival] => stdClass Object
(
[iataCode] => LAX
[terminal] => 3
[at] => 2021-07-30T08:22:00
)
[carrierCode] => TP
[number] => 4325
[aircraft] => stdClass Object
(
[code] => 32S
)
[operating] => stdClass Object
(
[carrierCode] => B6
)
[duration] => PT5H52M
[id] => 154
[numberOfStops] => 0
[blacklistedInEU] =>
)
)
)
)
[price] => stdClass Object
(
[currency] => USD
[total] => 845.85
[base] => 581.00
[fees] => Array
(
[0] => stdClass Object
(
[amount] => 0.00
[type] => SUPPLIER
)
[1] => stdClass Object
(
[amount] => 0.00
[type] => TICKETING
)
)
[grandTotal] => 845.85
)
[pricingOptions] => stdClass Object
(
[fareType] => Array
(
[0] => PUBLISHED
)
[includedCheckedBagsOnly] => 1
)
[validatingAirlineCodes] => Array
(
[0] => TP
)
[travelerPricings] => Array
(
[0] => stdClass Object
(
[travelerId] => 1
[fareOption] => STANDARD
[travelerType] => ADULT
[price] => stdClass Object
(
[currency] => USD
[total] => 845.85
[base] => 581.00
)
[fareDetailsBySegment] => Array
(
[0] => stdClass Object
(
[segmentId] => 152
[cabin] => ECONOMY
[fareBasis] => LUKBSI0D
[class] => L
[includedCheckedBags] => stdClass Object
(
[quantity] => 1
)
)
[1] => stdClass Object
(
[segmentId] => 153
[cabin] => ECONOMY
[fareBasis] => LUKBSI0D
[class] => L
[includedCheckedBags] => stdClass Object
(
[quantity] => 1
)
)
[2] => stdClass Object
(
[segmentId] => 154
[cabin] => ECONOMY
[fareBasis] => LUKBSI0D
[brandedFare] => BASIC
[class] => L
[includedCheckedBags] => stdClass Object
(
[quantity] => 1
)
)
)
)
)
)
Or anyone know if there are any other api's that I can use to get the logos?
Please help to get flight logo using Amadeus API
I have used Amadeus test API
Thank you
I am trying to unset/remove some elements from a multidimeansional usign the below code but i cant figure it out how.
My array looks like (only two elements from my multidimensional array)
[3] => stdClass Object
(
[processId] => H7-99440469
[hotelCode] => TR4SWV
[availabilityStatus] => InstantConfirmation
[totalPrice] => 36
[totalTax] => 0
[totalSalePrice] => 0
[currency] => EUR
[boardType] => All Inclusive
[rooms] => Array
(
[0] => stdClass Object
(
[roomCategory] => Double Promotional
[paxes] => Array
(
[0] => stdClass Object
(
[paxType] => Adult
[age] => 30
)
[1] => stdClass Object
(
[paxType] => Adult
[age] => 30
)
)
[totalRoomRate] => 36
[ratesPerNight] => Array
(
[0] => stdClass Object
(
[date] => 2015-05-01
[amount] => 36
)
)
)
)
)
[4] => stdClass Object
(
[processId] => HH-46795719
[hotelCode] => TRIIFY
[availabilityStatus] => InstantConfirmation
[specialDeal] => 11
[totalPrice] => 38
[totalTax] => 0
[totalSalePrice] => 0
[currency] => EUR
[boardType] => All Inc.
[rooms] => Array
(
[0] => stdClass Object
(
[roomCategory] => Double Room
[paxes] => Array
(
[0] => stdClass Object
(
[paxType] => Adult
[age] => 30
)
[1] => stdClass Object
(
[paxType] => Adult
[age] => 30
)
)
[totalRoomRate] => 38
[ratesPerNight] => Array
(
[0] => stdClass Object
(
[date] => 2015-05-01
[amount] => 38
)
)
)
)
)
How can i remove all the elemets that dont have [specialDeal] => 11 ? [specialDeal] => 11 is the Early booking discount
for($i=0;$i<count($array);$i++) {
if (!(isset($array[$i]->specialDeal) && $array[$i]->specialDeal] === 11)) {
unset($array[$i]);
}
}
$otherspecialoffer = array();
foreach( $availHotels as $key=>$item ) {
if (!(isset($item->specialDeal) && $item->specialDeal === 11)) {
unset($availHotels[$key]);
} else {
$otherspecialoffer[$item->specialDeal] = $key;
}
}
I hae vthe below code
<?php
if (is_object($checkAvailability->availableHotels))
$hotelResponse[] = $checkAvailability->availableHotels;
$hotelResponse = $checkAvailability->availableHotels;
foreach ((array)$hotelResponse as $hnum => $hotel)
?>
$hotelResponse is a Multi-dimensional array
print_r($checkAvailability->availableHotels); is generating :
Array ( [0] => stdClass Object ( [processId] => H0-41925041 [hotelCode] => ITJHRV [availabilityStatus] => InstantConfirmation [totalPrice] => 1421 [totalTax] => 0 [totalSalePrice] => 1509.38 [currency] => EUR [boardType] => Breakfast Buffet [rooms] => Array ( [0] => stdClass Object ( [roomCategory] => Classic Double or Twin Room-1 queen bed [paxes] => Array ( [0] => stdClass Object ( [paxType] => Adult [age] => 30 ) [1] => stdClass Object ( [paxType] => Adult [age] => 30 ) ) [totalRoomRate] => 1421 [ratesPerNight] => Array ( [0] => stdClass Object ( [date] => 2015-04-20 [amount] => 203 ) [1] => stdClass Object ( [date] => 2015-04-21 [amount] => 203 ) [2] => stdClass Object ( [date] => 2015-04-22 [amount] => 203 ) [3] => stdClass Object ( [date] => 2015-04-23 [amount] => 203 ) [4] => stdClass Object ( [date] => 2015-04-24 [amount] => 203 ) [5] => stdClass Object ( [date] => 2015-04-25 [amount] => 203 ) [6] => stdClass Object ( [date] => 2015-04-26 [amount] => 203 ) ) ) ) ) [1] => stdClass Object ( [processId] => HA-51032431 [hotelCode] => ITRR5G [availabilityStatus] => InstantConfirmation [totalPrice] => 1590 [totalTax] => 0 [totalSalePrice] => 0 [currency] => EUR [boardType] => Bed & Breakfast [rooms] => Array ( [0] => stdClass Object ( [roomCategory] => Twin Room (Including Breakfast and Wi-Fi) [paxes] => Array ( [0] => stdClass Object ( [paxType] => Adult [age] => 30 ) [1] => stdClass Object ( [paxType] => Adult [age] => 30 ) ) [totalRoomRate] => 1590 [ratesPerNight] => Array ( [0] => stdClass Object ( [date] => 2015-04-20 [amount] => 197 ) [1] => stdClass Object ( [date] => 2015-04-21 [amount] => 197 ) [2] => stdClass Object ( [date] => 2015-04-22 [amount] => 239 ) [3] => stdClass Object ( [date] => 2015-04-23 [amount] => 239 ) [4] => stdClass Object ( [date] => 2015-04-24 [amount] => 239 ) [5] => stdClass Object ( [date] => 2015-04-25 [amount] => 239 ) [6] => stdClass Object ( [date] => 2015-04-26 [amount] => 240 ) ) ) ) ) )
How can i do that get every response by echoing them as below
<?php echo $hotel->hotelCode?>
<?php echo $hotel->totalPrice?>
As i understand i need to convert the 2d array into a object but from there i have no clue. Please help.
Try this:
$hotelCodes = array() ;
$availHotels = $checkAvailability->availableHotels ;
foreach($availHotels as $hotel){
$hotelCodes[] = $hotel->hotelCode ;
//echo $hotel->hotelCode ;
//echo $hotel->totalPrice ;
}
Now you have $hotelCodes array and access it like $hotelCodes[0], $hotelCode[1] and so more.