What is difference between for and for each loop.Please explain with a example.
The foreach loop works only on arrays, and is used to loop through each key/value pair in an array. The main difference is that, you can set the number of iterations in for loop by adjusting counter value. Whereas in foreach loop, the iterations depend on the number of values of the array.