This forum is now read-only. Please use our new forums at

For Loops in PHP Forum

View Course » View Exercise

1230 points
Submitted by
over 3 years ago

Why do this way?

Between the parentheses, we use the $numbers as $item) syntax to tell PHP: "For each thing in $numbers, assign that thing temporarily to the variable $item."

Why assign one variable to the other, to jump from element to element? Isn't there any other way to represent this in "foreach" loop?

0 votes


In foreach you use a key and a value :)
You just let the computer know that every item in the array can be accessed with that variable

450 points
Submitted by
over 3 years ago