I want to use a foreach with a variable, but this variable can be of many different types, for example NULL .
So, before foreach I am testing it:
if(is_array($var)){ foreach($var as ...
But I realized that it could also be a class that implements the Iterator interface. Maybe I'm blind, but how to check if a class implements an interface? Is there something like the is_a function or the inherits operator? I found class_implements , I can use it, but maybe there is something simpler?
And secondly, more importantly, I believe that this function exists, would it be enough to check if the variable is_array or "implements the Iterator interface" or do I need to check something else?
arrays php foreach
Voitcus Mar 24 '13 at 21:00 2013-03-24 21:00
source share