Warning output when $headers not an array

Wrapped for loop in if statement so no warning would be issued if the $headers variable is not an array.