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! Quote Link to comment 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. Quote Link to comment 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. 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.