This seems to be a simple question, but I cannot find a good answer. Is there a way to put a condition on a foreach loop? I would like something like this:
foreach ($array as $value WHILE $condition == true) {
Of course, I could just put an if condition inside the foreach loop like this:
foreach ($array as $value) { if($condition == true) {
The only thing I would like to stop the repetition of the array after the if condition becomes false, in order to improve performance. You do not have to go through the remainder of the foreach loop to determine that the condition is $ false when it becomes false.
Any suggestions? Is there something obvious?
source share