phpretard Posted February 13, 2009 Share Posted February 13, 2009 If there are no errors on the form submitted I get PHP errors. How can I change this to first check if the array is set before running this code? foreach ($errormessage as $error){ echo $error; } Thanks! Link to comment https://forums.phpfreaks.com/topic/145086-solved-check-if-array-exists/ Share on other sites More sharing options...
Psycho Posted February 13, 2009 Share Posted February 13, 2009 if (is_array($errormessage)) { foreach ($errormessage as $error) { echo $error; } } Or, better yet - in my opinion - declare the array at the beginning $errormessage = array(); Then check the count of errors: if (count($errormessage) > 0) { foreach ($errormessage as $error) { echo $error; } } I think that "reads" better to a human. Link to comment https://forums.phpfreaks.com/topic/145086-solved-check-if-array-exists/#findComment-761356 Share on other sites More sharing options...
phpretard Posted February 13, 2009 Author Share Posted February 13, 2009 Thank the human works great! Although I am actually from Gallgamar. Link to comment https://forums.phpfreaks.com/topic/145086-solved-check-if-array-exists/#findComment-761364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.