Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP, continue; on foreach(){ foreach(){

Tags:

foreach

php

Is there a way to continue on external foreach in case that the internal foreach meet some statement ?

In example

foreach($c as $v) {     foreach($v as $j)     {         if($j = 1)         {             continue; // But not the internal foreach. the external;         }     } } 
like image 494
KodeFor.Me Avatar asked Oct 20 '11 10:10

KodeFor.Me


People also ask

Can I use continue in foreach PHP?

Introduction. The continue statement is one of the looping control keywords in PHP. When program flow comes across continue inside a loop, rest of the statements in current iteration of loop are skipped and next iteration of loop starts. It can appear inside while, do while, for as well as foreach loop.

Can I use break in foreach PHP?

break ends execution of the current for , foreach , while , do-while or switch structure. break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of. The default value is 1 , only the immediate enclosing structure is broken out of.

What does PHP continue do?

The continue keyword is used to is used to end the current iteration in a for , foreach , while or do.. while loop, and continues to the next iteration.

What is the difference between break and continue in PHP?

The break statement terminates the whole iteration of a loop whereas continue skips the current iteration. The break statement terminates the whole loop early whereas the continue brings the next iteration early.


1 Answers

Try this, should work:

continue 2; 

From the PHP Manual:

Continue accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of.

here in the examples (2nd exactly) described code you need

like image 122
user973254 Avatar answered Sep 21 '22 22:09

user973254