Link to home
Start Free TrialLog in
Avatar of Lee Redhead
Lee RedheadFlag for United Kingdom of Great Britain and Northern Ireland

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:

<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>

Open in new window


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;
	}

Open in new window


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);

Open in new window


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
Avatar of Lee Redhead
Lee Redhead
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lee Redhead

ASKER

Silly mistake made originally with the lookup resulting it only one item to loop.