c3cris c3cris - 1 year ago 101
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.

Answer Source

Right, it isn't a Traversable.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download