Skip to main content

Posts

Showing posts from March, 2015

Warning: Invalid Argument Supplied For foreach()

Today while refreshing my programming knowledge (those I left once completed my college), I repeatedly encountered an error message "Warning: Invalid argument supplied for foreach()". I was trying to display the items received from a checkbox form on browser using the foreach() loop. I created one HTML form with facility to receive multiple inputs from users using "checkbox" and  pass them to action page using the method "POST". As we know, the multiple inputs create an  array which can be accessed using $_POST["name given to checkbox"] and displayed using foreach loop. However, instead of displaying the user inputs, I received the error message " Warning: Invalid argument supplied for foreach() ". You can see the browser response from the picture attached below.



Reason:
foreach() works for arrays and if the passed variable is not a valid array, we will get the "Invalid argument' warning. To avoid this warning and makes the pro…