phpcodec Posted June 21, 2008 Share Posted June 21, 2008 I have a foreach statement that ready off an array but when the array is empty the foreach prins an error "Warning: Invalid argument supplied for foreach() " how can i stop this error from showing? Quote Link to comment https://forums.phpfreaks.com/topic/111231-foreach/ Share on other sites More sharing options...
wildteen88 Posted June 21, 2008 Share Posted June 21, 2008 Check to make sure the variable you're passing to forearch is an array by using the is_array() function. if(is_array($array_var)) { foreach($arrar_var as $whatever) { // do something } } Quote Link to comment https://forums.phpfreaks.com/topic/111231-foreach/#findComment-570897 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.