Hi all, The array is dyn. being populated sometimes it has just one element. If it does my foreach statement doesn't work. How can i fix this?
sorry i must simplefy my code to post here But i made a mistake it turns out my array consists of arrays. And i have the problem when it my array just has one array. In the case my array has one arrayA as an element. The sizeof($myArray) is the length of arrayA and not 1??? //working $roomsAvailable = [ Array ( [TotalRate] => 460]; ) Array ( [TotalRate] => 230]; ) ] //non working $roomsAvailable = Array ( [TotalRate] => 460]; ) Code (markup): foreach($roomsAvailable as $rooms => $value) { $totalPrice = $value['TotalRate']; } Code (markup): Hope you get what i am after?
Array ( [RoomType] => wert [RoomDescription] => wert [InfoText] => [MinimumRate] => 105 [MaximumRate] => 105 [ArrivalRate] => 105 [ArrivalTax] => 0 [TotalRate] => 105 [TotalTax] => 0 [Available] => true [Rates] => Array ( [RateDate] => Array ( [Date] => 2007-08-25T00:00:00 [Rate] => 105 [MealplanRate] => 0 [Tax] => 0 ) ) ) Code (markup): here i can use count or sizeof Array ( [0] => Array ( [RoomType] => er [RoomDescription] => ewrt [InfoText] => [MinimumRate] => 125 [MaximumRate] => 125 [ArrivalRate] => 125 [ArrivalTax] => 0 [TotalRate] => 125 [TotalTax] => 0 [Available] => true [Rates] => Array ( [RateDate] => Array ( [Date] => 2007-08-29T00:00:00 [Rate] => 125 [MealplanRate] => 0 [Tax] => 0 ) ) ) [1] => Array ( [RoomType] => asdf [RoomDescription] => asdfr [InfoText] => [MinimumRate] => 125 [MaximumRate] => 125 [ArrivalRate] => 125 [ArrivalTax] => 0 [TotalRate] => 125 [TotalTax] => 0 [Available] => true [Rates] => Array ( [RateDate] => Array ( [Date] => 2007-08-29T00:00:00 [Rate] => 125 [MealplanRate] => 0 [Tax] => 0 ) ) ) ) Code (markup):
ok this is my problem (described better by someone else) http://nl3.php.net/manual/en/function.soap-soapclient-soapcall.php#74263 Now here's an answer but i don't get it http://nl3.php.net/manual/en/function.soap-soapclient-soapcall.php#75797
Pretty much, they're telling you to do this: function getArrayFromResponse($data) { if (sizeof($data) < 2) { $new = array(); $new[] = $data; return $new; } return $data; } foreach(getArrayFromResponse($roomsAvailable) as $rooms => $value) { PHP: Try this.
Don't know if this makes it less confusing, but here's another way of showing the same thing: // If it's not an array of arrays, make it into one if (!isset($roomsAvailable[0])) $roomsAvailable = array($roomsAvailable); foreach($roomsAvailable as $rooms => $value) { $totalPrice = $value['TotalRate']; } Code (markup):
@ssanders82, thx for thinking along but i found this solution function getArrayFromResponse($data) { $test = is_array($data)?$data:array($data); if(is_array($test[0])) { $data = $data; } else { $data = array($data); } return $data; } Code (markup):