hno Posted August 21, 2010 Share Posted August 21, 2010 HI, I have a foreach loop but after some execution it begins to show me this:Invalid argument supplied for foreach() ... so I want to exit from it.how can I do that? Thanks Link to comment https://forums.phpfreaks.com/topic/211344-how-to-exit-foreach-at-the-following-statement/ Share on other sites More sharing options...
Alex Posted August 21, 2010 Share Posted August 21, 2010 Use break; to break out of a loop. foreach(...) { if(...) { break; } } Link to comment https://forums.phpfreaks.com/topic/211344-how-to-exit-foreach-at-the-following-statement/#findComment-1101978 Share on other sites More sharing options...
hno Posted August 21, 2010 Author Share Posted August 21, 2010 Use break; to break out of a loop. foreach(...) { if(...) { break; } } Yeah I know ,I what I wanted to do is this when there is an error which says "Invalid argument supplied for foreach()" we exit the loop.How can I do so? Link to comment https://forums.phpfreaks.com/topic/211344-how-to-exit-foreach-at-the-following-statement/#findComment-1101981 Share on other sites More sharing options...
Alex Posted August 21, 2010 Share Posted August 21, 2010 You have nested foreach loops or what? Just make sure that the variable you're performing the foreach on is an array using is_array. Link to comment https://forums.phpfreaks.com/topic/211344-how-to-exit-foreach-at-the-following-statement/#findComment-1101985 Share on other sites More sharing options...
hno Posted August 21, 2010 Author Share Posted August 21, 2010 You have nested foreach loops or what? Just make sure that the variable you're performing the foreach on is an array using is_array. Look,I think some of the last element of that has problem because first I print the elements of the array but when we appreciate to the end of the array it begins to shows me that. Is there any solution? Link to comment https://forums.phpfreaks.com/topic/211344-how-to-exit-foreach-at-the-following-statement/#findComment-1101987 Share on other sites More sharing options...
trq Posted August 21, 2010 Share Posted August 21, 2010 Post your code. Your obviously doing something incorrectly. Link to comment https://forums.phpfreaks.com/topic/211344-how-to-exit-foreach-at-the-following-statement/#findComment-1101990 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.