Software Development

How to fix “Warning: Invalid argument supplied for foreach()” in PHP

Background

[wp_ad_camp_5]

If you’re creating an application from ground up, you may already have coded or even designed the core components to check for and avoid non-traversable parameters in some methods or functions that use these variables in foreach statements within them. However, if you are modifying an existing and unfamiliar application you would want to keep the changes localized to avoid affecting other parts of the program. In the case for foreach, a simple check of the arguments can be performed on them before passing to the looping construct.

This article demonstrates how to perform checking on a variable to determine whether it is traversable to not before letting foreach use it.

Software Requirements

  • Windows 7 Professional SP1
  • PHP 5.5.9 / Zend Engine v2.5.0
  • NetBeans IDE 8.0.1

The Codes

[wp_ad_camp_3]

[wp_ad_camp_4]

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like