Include iteration in iterator

PHP 7.1 introduced a new iterablepseudo-type .

Is there an easy way to convert common iterableto Iterator? Or should I use something like

if (is_array($iterable)) {
    return new \ArrayIterator($iterable);
}

return new \IteratorIterator($iterable);
+1
source share

All Articles