
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How can I break an outer loop with PHP?
If there are two nested loops, the break statement can be used −
break 2;
Below is a demonstration with 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, the below lines of code can be used −
foreach (...) { foreach (...) { if (my_var_1.name == my_var_2) goto top; } } top:
- Related Articles
- How can I write in order with for loop or while loop?
- How can I use a label with break statement in JavaScript?
- How to use PowerShell Break statement with the While Loop?
- How to use PowerShell break statement with the For loop?
- How to break a loop in JavaScript?
- How to break a for loop in Python?
- In PHP, how can I add an object element to an array?
- PHP break Statement
- How to use PowerShell break statement in foreach loop?
- How to break out of a loop in Perl?
- How do you create a Tkinter GUI stop button to break an infinite loop?
- break, continue and label in Java loop
- How can I loop over entries in JSON using Python?
- PHP foreach Loop.
- How we can break a string with multiple delimiters in Python?

Advertisements