I have this problem where an API responds to me with DEPARTURESEGMENT sometimes containing only one object, and sometimes containing an array of objects. Depending on which case
How about checking whether it's an array or not with is_array? I made a simple example of it's usage here - http://codepad.org/WNjbIPZF