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 Link to comment https://forums.phpfreaks.com/topic/215243-breaking-one-cycle-of-a-foreach/ 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 } } Link to comment https://forums.phpfreaks.com/topic/215243-breaking-one-cycle-of-a-foreach/#findComment-1119434 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 Link to comment https://forums.phpfreaks.com/topic/215243-breaking-one-cycle-of-a-foreach/#findComment-1119436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.