Invalid argument supplied for foreach()

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.

Leave a Comment