PHP loop Condition, it can be used to traverse the set of code for the specified number of times and The loopfor is used when you know in advance that how many times the script should run. It should be used if a number of iteration is known otherwise used while loop Condition.
For loop Condition and loop Condition in PHP Programming, We can also use for loop inside for loop in PHP, it is called as nested for loop.
In case of inner or nested for loop, nested for loop is executed fully for one outer for loop. If outer for loop is to be executed for 3 times and inner for loop for 3 times, inner for loop will be executed 9 times (3 times for 1st outer loop, 3 times for 2nd outer loop and 3 times for 3rd outer loop).
PHP For Each Loop-
The loopfor each works only on arrays and is used to loop through each key/value pair in an array or PHP for each loop is used to traverse array elements.
code tobe executed;
For every loop iteration in a foreach loop, the value of the current array element is assigned to $value and the array pointer is moved by one until it reaches the last array element.
The following example demonstrates a loop that will output the values of the given array ($colors):