What are the differences between the for
loop and the foreach
loop in PHP?
for loop is used if we know already that how many times the script should be run but in the case of foreach loop, we don't have any idea about the number of iteration.
Also foreach loop is used to iterate only arrays and objects.
You can refer the link for better understanding the difference between for and foreach loop -
https://www.quora.com/What-is-the-difference-between-for-and-foreach-in-php