Invalid argument supplied for foreach()
How about this one? lot cleaner and all in single line.
foreach ((array) $items as $item) {
// ...
}
Personally I find this to be the most clean - not sure if it's the most efficient, mind!
if (is_array($values) || is_object($values))
{
foreach ($values as $value)
{
...
}
}
The reason for my preference is it doesn't allocate an empty array when you've got nothing to begin with anyway.