c3cris c3cris - 4 months ago 21
PHP Question

Is an array an instance of Traversable?

Here is my basic array in my framework

array(2) {
[0]=>
string(2) "40"
[1]=>
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.

Answer

Right, it isn't a Traversable.

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