- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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:
Advertisements