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:

if (in_array($arrItem)) {
foreach($arrItem as $arrItemi) {
// use $arrItemi;
}
}