Ok, so I'm requesting state and city from a service using SOAP and using a 'foreach' loop to output the states, and within each of those iterations, I'm using another 'foreach' loop to output the cities within each state.
First, the SOAP call:
$client = new SoapClient("https://devxml.#####.com/golfService.asmx?wsdl", array(‘features’ => SOAP_SINGLE_ELEMENT_ARRAYS));
$regionList = $client->Areas(
array(
'Hdr' => array(
'ResellerId' => '#####',
'SourceCd' => 'A',
'UserIp' => '207.58.123.121',
'gsDebug' => '1'
),
'Req' => array(
'CountryID' => 'USA',
'RegionID' => ''
)
)
)
...which returns the following the XML:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AreasResponse xmlns="http://xml.####.com/">
<AreasResult>
<RetCd>0</RetCd>
<RetMsg />
<Countries>
<Country>
<id>USA</id>
<nm>United States</nm>
<Regions>
<Region>
<id>AZ</id>
<nm>Arizona</nm>
<Areas>
<Area>
<id>Phoenix Northeast</id>
<nm>Phoenix Northeast</nm>
</Area>
</Areas>
</Region>
<Region>
<id>FL</id>
<nm>Florida</nm>
<Areas>
<Area>
<id>Ft. Myers/Naples</id>
<nm>Ft. Myers/Naples</nm>
</Area>
<Area>
<id>Miami / Ft. Lauderdale</id>
<nm>Miami / Ft. Lauderdale</nm>
</Area>
</Areas>
</Region>
</Regions>
</Country>
</Countries>
</AreasResult>
</AreasResponse>
</soap:Body>
</soap:Envelope>
Now, here's how I'm handling this in my PHP:
foreach ($regionList->AreasResult->Countries->Country->Regions->Region as $region):
echo $region->nm . ": ";
foreach ($region->Areas->Area as $area):
echo $area->nm . ", ";
endforeach;
echo "<br />";
endforeach;
Ideally, this would output as:
Arizona: Phoenix Northeast,
Florida: Ft. Myers/Naples, Miami / Ft. Lauderdale,
But no! It's showing up like this:
Arizona: , ,
Florida: Ft. Myers/Naples, Miami / Ft. Lauderdale,
The two commas after 'Arizona:' imply there are two records, but there's only one. Even more infuriating is that it won't output the dang Area value. What am I doing wrong? Help me, StackOverflow, you're my only hope!
foreach ($region->Areas->Area)?