The PHP foreach loop will help to iterate over an array or object. Please check the following foreach loop execution animation.
PHP Foreach Syntax
1 2 3 |
foreach ($array_or_object as $value){ //statement here } |
OR
1 2 3 |
foreach ($array_or_object as $key => $value){ //statement here } |
How it is working?
It is moving through each array element in every iteration. The value of the array key and the value of each element are assigned during each iteration.