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? 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 } } Link to comment https://forums.phpfreaks.com/topic/111231-foreach/#findComment-570897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.