checks for array before calling foreach to remove php warnings