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 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 :)