ballhogjoni Posted July 24, 2008 Share Posted July 24, 2008 how would you stop a foreach loop in the middle of the loop? My thoughts are having an if statement like: foreach() { $a = 1+4; if($a!=5){ break; } } Link to comment https://forums.phpfreaks.com/topic/116439-how-to-stop-a-foreach-loop/ Share on other sites More sharing options...
ranjuvs Posted July 24, 2008 Share Posted July 24, 2008 chg the condition as below.. foreach() { $a = 1+4; if($a>=5){ break; } } Link to comment https://forums.phpfreaks.com/topic/116439-how-to-stop-a-foreach-loop/#findComment-598812 Share on other sites More sharing options...
JonnyThunder Posted July 24, 2008 Share Posted July 24, 2008 It's better programming practice to control the loop, rather than to break out of it. Link to comment https://forums.phpfreaks.com/topic/116439-how-to-stop-a-foreach-loop/#findComment-598816 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.