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 Quote Link to comment 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; } } Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. 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.