A common error which occurs with foreach loops is the standard “Invalid argument supplied for foreach()” whch gets thrown up as a warning.

This can easily be overcome by wrapping the foreach loop in a conditional if statement which checks to see if the argument supplied to the loop is an array or not.

Below is an example of how to correct the problem:

[code lang=”php”]
if (in_array($arrItem)) {
foreach($arrItem as $arrItemi) {
// use $arrItemi;
}
}
[/code]

Categories: ContentGeneral

1 Comment

CyrIng · May 11, 2012 at 12:40

Hi,

I’m rather using is_array since in_array require two arguments

Leave a Reply

Your email address will not be published. Required fields are marked *