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

For Loops in PHP Forum

View Course » View Exercise

1230 points
542106ae8c1ccc2c1100199c_498535755
Submitted by
Anurag
almost 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

permalink

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
5240e713abf821aa28001257_703076796
Submitted by
Robinvb
almost 3 years ago