: This article describes the PHP-Traversable interface. For more information about PHP tutorials, see. Traversable is used to check whether a class can be traversed using foreach. this is an internal engine interface that cannot be implemented in PHP scripts. in actual programming, we use the Iterator interface or the IteratorAggregate interface to implement traversal.
Interface abstract:
Traversable {}
An important use of Traversable is to determine whether a class can be traversed. The following is an official example:
It should be noted that Arrays and objects can be traversed through foreach, but they do not implement the Traversable interface, so it is not an example of Traversable:
The above code output:
booleanfalse
booleanfalse
Note:
When the class does not implement the Iterator interface or the IteratorAggregate interface, executing the foreach traversal will output all the visible attributes that can be accessed by the class.
The above describes the PHP-Traversable interface details, including the content, hope to be helpful to friends who are interested in PHP tutorials.