Lee Redhead
asked on
PHP SimpleXML foreach loop not looping
Hi,
I have a rather odd problem relating to a XML lookup and the foreach loop not actually looping.
The XML data I am trying to read is ask follows:
This extract comes from a larger file under the main section <details>.
So my loop is setup as follows:
All that does however is output the 1st "Item A", nothing else.
If I do the following then it outputs: 4 as I would expect as there are 4 items.
Am I missing something? This has worked perfectly in other sections of the file, although there have been other values contained within the particular tag in those cases.
Thanks.
I have a rather odd problem relating to a XML lookup and the foreach loop not actually looping.
The XML data I am trying to read is ask follows:
<bullets>
<bullet id="1">
Item A
</bullet>
<bullet id="2">
Item B
</bullet>
<bullet id="3">
Item C
</bullet>
<bullet id="4">
Item D
</bullet>
</bullets>
This extract comes from a larger file under the main section <details>.
So my loop is setup as follows:
$details = simplexml_load_file("some.xml");
foreach($details->bullets as $bullets) {
echo $bullets->bullet;
}
All that does however is output the 1st "Item A", nothing else.
If I do the following then it outputs: 4 as I would expect as there are 4 items.
foreach($details->bullets as $bullets) {
// DO NOTHING
}
echo count($bullets);
Am I missing something? This has worked perfectly in other sections of the file, although there have been other values contained within the particular tag in those cases.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER