Please an is_array() check before the foreach.