Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Simple PHP Application Listing Inventory Items Introducing Arrays

Count function not working

Please help

5 Answers

Matt Campbell
Matt Campbell
9,767 Points

Need a bit more information. What code are you writing? What is it doing or what is it not doing?

Please provide the correct code so that i can check

Matt Campbell
Matt Campbell
9,767 Points

I don't know what you're wanting to do. If it's in a foreach loop, then each time the loop runs, you need to add 1 to your count variable.

How we add that?

Matt Campbell
Matt Campbell
9,767 Points

http://stackoverflow.com/questions/6220546/count-number-of-iterations-in-a-foreach-loop

Google is your friend!

That's just counting how many things are spat out of the foreach loop. You can move onto using print_f and add the count as ids and stuff.