Question about the php loop jumping out

  • 2020-06-23 00:07:37
  • OfStack


//php The current loop is 1 , the loop increases from the inside out, break The default is 1 , such as jumping out of the box 2 Layer circulation 
for ($i=0;$i<3;$i++){
    foreach (array(1,2,3) as $val){     
        foreach (array(1,2,3) as $val){          
            echo "1 Layer circulation <br/>";  
            break 2;  // Jump out of the first 2 Layer circulation          
        }
        echo "2 Layer circulation <br/>";
    }
    echo "3 Layer circulation <br/>";
}
// Results: 
//1 Layer circulation 
//3 Layer circulation 
//1 Layer circulation 
//3 Layer circulation 
//1 Layer circulation 
//3 Layer circulation 

Related articles: