Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Jun XIE
10,363 Pointswhy 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

Adam Duffield
30,494 PointsI'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.
Jun XIE
10,363 PointsJun XIE
10,363 PointsThanks, ^_^. "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.
Adam Duffield
30,494 PointsAdam Duffield
30,494 PointsNo 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 ;)