dadamssg87 Posted December 9, 2011 Share Posted December 9, 2011 Is there a way to tell the loop you are iterating through to move onto the next item if a certain condition is met without having a bunch of nested if statements? <?php foreach($item as $key => $value) { //code to manipulate the data if($data == $condition1){ //move on to next item} //manipulate data more if($data == $condition2){ //move on to next item} //manipulate data even more if($data == $condition3){ //move on to next item} //you get the idea } Link to comment https://forums.phpfreaks.com/topic/252841-move-onto-next-item-in-loop-without-a-bunch-of-if-statements/ Share on other sites More sharing options...
scootstah Posted December 9, 2011 Share Posted December 9, 2011 Can you give a real-world example? Link to comment https://forums.phpfreaks.com/topic/252841-move-onto-next-item-in-loop-without-a-bunch-of-if-statements/#findComment-1296300 Share on other sites More sharing options...
jcbones Posted December 9, 2011 Share Posted December 9, 2011 <?php foreach($item as $key => $value) { if($key == 'Today') { continue; //move to next item key. } echo $key . '=' . $value . "<br />\n"; } Continue. Link to comment https://forums.phpfreaks.com/topic/252841-move-onto-next-item-in-loop-without-a-bunch-of-if-statements/#findComment-1296320 Share on other sites More sharing options...
cs.punk Posted December 9, 2011 Share Posted December 9, 2011 What you probably are looking for is the break statement: break ends execution of the current for, foreach, while, do-while or switch structure. Link to comment https://forums.phpfreaks.com/topic/252841-move-onto-next-item-in-loop-without-a-bunch-of-if-statements/#findComment-1296398 Share on other sites More sharing options...
Andy-H Posted December 9, 2011 Share Posted December 9, 2011 What you probably are looking for is the break statement: break ends execution of the current for, foreach, while, do-while or switch structure. Nope, what jcbones said, continue Link to comment https://forums.phpfreaks.com/topic/252841-move-onto-next-item-in-loop-without-a-bunch-of-if-statements/#findComment-1296400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.