0

What différence betwen for and foreach ?

25th Jul 2018, 9:25 AM
scott Trésor
scott Trésor - avatar
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
25th Jul 2018, 10:13 AM
Ipang
+ 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 .
25th Jul 2018, 10:36 AM
Maninder $ingh
Maninder $ingh - avatar
+ 1
"foreach" working slower than "for"
25th Jul 2018, 9:35 AM
ValterHeroツ
ValterHeroツ - avatar
+ 1
for is a loop whereas foreach is an method of array. Hope this helps â˜șâ˜ș.
25th Jul 2018, 10:07 AM
Meet Mehta
Meet Mehta - avatar