I am looking to break an outer for/foreach loop in PHP.
This can be done in ActionScript like so:
top : for each(var i:MovieClip in movieClipArray)
{
for each(var j:String in nameArray)
{
if(i.name == j) break top;
}
}
What's the PHP equivalent?
You can using just a break-n statement:
If you're in php >= 5.3, you can use labels and
goto
s, similar as in action script:But goto must be used carefully. Goto is evil (considered bad practice)
Use goto?
You can use
break 2;
to break out of two loops at the same time. It's not quite the same as your example with the "named" loops, but it will do the trick.In the case of 2 nested loops:
http://php.net/manual/en/control-structures.break.php
PHP Manual says