How to break outer loop using PHP?

PHPz
Release: 2023-08-29 15:22:01
forward
997 people have browsed it

How to break outer loop using PHP?

If there are two nested loops, you can use the break statement-

break 2;
Copy after login

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
   }
}
Copy after login

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:
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!