Razvan
Razvan

Reputation: 63

Split multidimensional array from SOAP response

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.

Upvotes: 1

Views: 254

Answers (1)

Riad
Riad

Reputation: 3850

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.

Upvotes: 1

Related Questions