It starts only once. foreach will work with a copy of the explode return value (array or false).
foreach is a language construct that expects $array as $key => $value . $array can be any expression that evaluates an array, and explode is such a function. An expression is evaluated only once, and then foreach works with the result of the expression.
This is different from a regular for loop, for example. The for loop accepts three expressions. Both the second and third expressions are evaluated for each iteration of the loop.
Thus, there may be a difference with the for loop (leaving optimization and the O (1) action count aside) between these two statements:
for($i = 0; $i < count($array); ++$i) { … } // vs. for($i = 0, $c = count($array); $i < $c; ++$i) { … }
source share