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 the browser using the foreach() loop. I created one HTML form with the 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 the 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 ma…

About Author

My photo
Alex George
Alex George has Engineering graduation in Computer Science and an MBA in Finance. He had been working as a senior Network Engineer for ten years. His specialization is in Cisco products. Traveling is one of his hobbies and visited various places as part of his onsite work. He visited different places as part of his onsite work like New York, Dubai, London, etc. Right now Alex is a director of one of the leading career development firms in India, which trains students for UPSC, SSC, and PSC examinations. He guides a lot of students to get selection for various prestigious institutions like CBI, Income Tax Department, etc. Alex George is a stock market investor and a very active intraday trader. Engineering Background: He has a B.Tech in Computer Science and Engineering and passed different network and security courses like CCNA, CCNP (Security), CEH, and various Microsoft certifications. Finance Background: Alex has an MBA in Finance. He is an active intraday trader and a Share Market Investor. Webmaster Skills: Alex is a blogger since 2004. He has a working knowledge of HTML, CSS, PHP, and JavaScrip.