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 Working With Functions Working with Functions

why is "foreach" not a function?

I don't know why foreach is not a function. By "foreach", we will have some results, like some texts are echoed out. Thanks in advance!

1 Answer

I'm only just still learning in PHP myself but I think it is because foreach is a construct that requires specific elements to work whereas a function like count() you can use on just about everything. Hope this helps.

Thanks, ^_^. "requires specific elements to work" reminds me that, foreach is really different from the date() and count() functions in terms of the form of arguments.

No problem dude, if your not already I'd advise having a good quick read of the site's displayed in the notes that go into detail on the functions your using. Really helps you feel like you've nailed that lesson if you know what I mean ;)