Omirion Posted October 5, 2010 Share Posted October 5, 2010 Hey guys, How can i break just one cycle of a foreach loop. Example: $arr = array('0','1','2'); foreach ($arr as $value){ if($value == 1){ break from this iteration and continue onto next one} echo $value; } So the output should be 02 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 5, 2010 Share Posted October 5, 2010 very close. you use break; foreach ($arr AS $value) { if ($value == 1) { break; } } but if you just want to skip the iteration, use continue instead [code] foreach ($arr AS $value) { if ($value == 1) { continue; // skip to the next $value } } Quote Link to comment Share on other sites More sharing options...
Omirion Posted October 5, 2010 Author Share Posted October 5, 2010 I got it I need continue though. Cause break stops the loop altogether. 10x fro the speedy response Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.