Page 1 of 1

foreach loop Counter Not working...?

Posted: Mon Dec 14, 2009 5:52 pm
by imsoconfused
Hello everyone.

I am trying to count the different elements in an xml sheet using SIMPLE XML with no luck

function findTotal()
{
$count=0; //variable holding the

foreach($xml->weddings as $item)
{
$count+=1;
}
echo 'this is the last item: ' . $count;
}

am i doing something wrong? how do i count the iterations of the foreach loop and assign it to variable count correctly?

Re: foreach loop Counter Not working...?

Posted: Mon Dec 14, 2009 6:49 pm
by requinix
You can just use count for this.