Is there an is_iterable or similar function for PHP?

Possible duplicate:
Iterable objects and hinting array type?

I pass the JSON'd channel from Twitter to my application, and sometimes the Twitters API returns empty or incomplete channels. This causes a problem when I try to iterate through channels using foreach . Does anyone know a suitable test to find out if an object or array is iterable?

Is it possible to do this with isarray($obj) || $obj instanceof Iterator isarray($obj) || $obj instanceof Iterator or are there any other cases I should look for?

+4
source share

All Articles