How can I detect the variable is a Traversable
object to use in foreach
loops?
if(is_traversable($variable)) {
return (array) $variable;
}
Use instanceof
to determine if the object is Traversable
if($variable instanceof \Traversable) {
// is Traversable
}