If there are two nested loops, you can use the break statement-
break 2;
The following is a demonstration of the foreach loop-
foreach(...) { foreach(...) { if (my_var_1.name == my_var_2) break 2; //it breaks out of the outermost foreach loop } }
For PHP version> =5.3, you can use the following line of code -
foreach (...) { foreach (...) { if (my_var_1.name == my_var_2) goto top; } } top:
The above is the detailed content of How to break outer loop using PHP?. For more information, please follow other related articles on the PHP Chinese website!