foreach loop Counter Not working...?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
imsoconfused
Forum Newbie
Posts: 15
Joined: Mon Oct 05, 2009 10:55 pm

foreach loop Counter Not working...?

Post 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?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: foreach loop Counter Not working...?

Post by requinix »

You can just use count for this.
Post Reply