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.

PHP Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Working with Functions

Andrew Hartley
Andrew Hartley
2,750 Points

Why is foreach not considered a PHP function? Is an array function considered different from a function like count?

Questioning the quiz question "Which of the following is not a PHP function?"

count, isset, and date are PHP functions, but foreach is not? An array function is not a function? I am totally confused by this question. Can anybody enlighten me?

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I'm not exactly sure what you mean by an array function. However, foreach is a loop which is considered a language construct much the same way an if/else statement is considered a construct. That being said, I'm also given to understand that technically speaking $isset() is also a language construct and not a function. I will check up on that, though :smiley:

The idea here is that some things are hard-coded into the language and some were added by other programmers to become part of the language. They are considered to be constructs.

Hope this helps! :sparkles:

Andrew Hartley
Andrew Hartley
2,750 Points

Thanks, Jennifer, that does help.

In response to your statement about what I meant by "array function" I just googled and the resulting blurb said something about "array function" (I did not click through - I probably should have).

The "construct" vs. "function" dichotomy makes sense, though they seem to work in a similar fashion - e.g. name(arguments/operators) {things it does;} - hence my confusion with the question in the quiz.

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

I agree that this question is confusing, I'm going to remove it :)