illustrate
1. When executing the foreach object, it is automatically called and the traversal method is specified.
2. Iterator is a predefined interface class in PHP and can be used directly. iterator{} is a subclass of Traversable{}.
Traversable{} is an interface that checks whether a category can use foreach.
Example
Iterator extends Traversable { abstract public current(): mixed — Returns the current element abstract public key(): scalar — Returns the key of the current element abstract public next(): void — Moves forward to the next element abstract public rewind(): void — Returns to the iteration The first element of the container abstract public valid(): bool — Check whether the current position is valid}
The above is the function of php iterator, I hope it will be helpful to everyone.