我希望在PHP中打破外部for/foreach循环.
这可以在ActionScript中完成,如下所示:
top : for each(var i:MovieClip in movieClipArray)
{
for each(var j:String in nameArray)
{
if(i.name == j) break top;
}
}
Run Code Online (Sandbox Code Playgroud)
什么是PHP等价物?
在我工作的许多项目中,我发现我有嵌套for循环(我将专注于PHP实现,但也适用于javascript)采用这种通用形式:
$array1 = array(........);
$count1 = count($array1);
$invalidState = false;//An invalid state will be looked for in the innermost loop, and if found, break all the loops
for($i = 0; $i < $count1; $i++) {
//parsing, then another loop
$array2 = explode("needle", $array1[$i]);
$count2 = count($array2);
for($j = 0; $j < $count2; $j++) {
//parsing, then sometimes even another another loop
$array3 = explode("different-needle", $array2[$j]);
$count3 = count($array3);
for($k = 0; $k < $count3; $k++) {
//check for …Run Code Online (Sandbox Code Playgroud)