php - foreach not looping correctly for a webservice -


i have , array being produced webservice.

array (      [tpa_extensions] => array (         [tparoomdetail] => array (              [guestcounts] => array (                  [guestcount] => array (                          [!agequalifyingcode] => 10                          [!count] => 1                 )              )              [!occupancy] => single              [!occupancycode] => sgl          )      )      [!isroom] => true      [!quantity] => 1      [!roomtype] => palace gold club room      [!roomtypecode] => pgc  ) 

my foreach loop below

foreach ($roomtype["tpa_extensions"]["tparoomdetail"]["guestcounts"]["guestcount"] $guestcount) {  echo "guest count1->";print_r($guestcount); echo "guest count2->";  print_r($roomtype["tpa_extensions"]["tparoomdetail"]["guestcounts"]["guestcount"]); } 

the output guest

count1->10 guest count2->array ( [!agequalifyingcode] => 10 [!count] => 1 )  

guest count1 should have been array

array ( [!agequalifyingcode] => 10 [!count] => 1 )  comes int 10 .. 

why ..?

your output correct, $guestcount holds number '10',

where $roomtype["tpa_extensions"]["tparoomdetail"]["guestcounts"]["guestcount"] hold array.

this loop:

foreach ($roomtype["tpa_extensions"]["tparoomdetail"]["guestcounts"]["guestcount"] $guestcount) {    echo "guest count1->";print_r($guestcount);   echo "guest count2->";  print_r($roomtype["tpa_extensions"]["tparoomdetail"]["guestcounts"]["guestcount"]); } 

ths loop run 2 times, because that's number of childs in guestcount array. '10', '1', reflecting structure of array:

[!agequalifyingcode] => 10  [!count] => 1 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -