A question about loop jumping in php

WBOY
Release: 2016-07-25 09:07:25
Original
811 people have browsed it
  1. //The current loop of php is 1, and the loop increases from the inside to the outside. The break defaults to 1, for example, jumping out of the second layer of loop

  2. for ($i=0; $i<3;$i++){
  3. foreach (array(1,2,3) as $val){
  4. foreach (array(1,2,3) as $val){
  5. echo "1-level loop
    ";
  6. break 2; //Jump out of the 2nd level loop
  7. }
  8. echo "2nd level loop
    ";
  9. }
  10. echo "3rd level loop
    ";
  11. }
  12. //Result:
  13. //1 layer loop
  14. //3 layer loop
  15. //1 layer loop
  16. //3 layer loop
  17. //1 layer loop
  18. //3 layer loop
  19. ?>

Copy code


source:php.cn
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!