0
What différence betwen for and foreach ?
4 Answers
+ 3
These links didn't cover the difference between for & foreach in particular language (PHP in this case), but they may serve as a general guide to distinguish the difference, and usage preferences of the two loops:
https://www.differencebetween.com/difference-between-for-loop-and-vs-foreach-loop/
https://www.codeproject.com/questions/655838/difference-between-for-and-foreach-loop
Hth, cmiiw
+ 3
For loop repeatedly execute a statement until a specified execution evaluates to false..Â
for loop is maintained in condition level... it executed 0 or more timesÂ
While for each loop repeats a group of embedded statements for each elements in a array or object collectionÂ
For each loop gets rid of the clutter and the opportunity for error by hiding the iterator or index variable completely,comprises less coding then for loop .
+ 1
"foreach" working slower than "for"
+ 1
for is a loop whereas foreach is an method of array.
Hope this helps âșïžâșïž.