c3cris c3cris - 2 months ago 17x
PHP Question

Is an array an instance of Traversable?

Here is my basic array in my framework

array(2) {
string(2) "40"
string(2) "41"

Here is my tests:

echo($array instanceof Traversable); // 0
echo(is_array($array)); // 1

It seems my standard php array is not an instance of Traversable which seems inconsistent.


Right, it isn't a Traversable.

The main goal of the interface Traversable is to make objects useable with foreach.