TehBotolSosro Posted March 15, 2011 Share Posted March 15, 2011 hi all, im still new with php, any my english are messed up so be patience anyway i have a code like this if ($Stop == "0") { foreach ($bot->fobjects as $obj) { if (($obj["className"] == "Home")) { echo "Running"; break; } else { echo "Not Running"; break; } } } the problem is, its not running the way it suppose to, as it always go to the else section even if there is an array with className Home inside the $bot->fobjects and when i do the obj var_dump below the echo "Not Running"; it always show the wrong array and the strange thing if i remove the else section, the code is working good and it show the correct array is there something wrong with my code? thank you Quote Link to comment https://forums.phpfreaks.com/topic/230694-else-in-foreach-problem/ Share on other sites More sharing options...
sasa Posted March 16, 2011 Share Posted March 16, 2011 remove break; commands from your code it's cause that just 1st loop execute Quote Link to comment https://forums.phpfreaks.com/topic/230694-else-in-foreach-problem/#findComment-1188053 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.