For vs Foreach

Foreach loops are more simple and appropriate for Associative arrays and when you don’t have to keep track of iterations. For Indexed arrays, For loops are more appropriate since their incrementers are nicely associated with the keys of Indexed arrays.

Share