Output.txt: Output

Straight traversal:
First
Second
Third
Reverse traversal:
Third
Second
First

Example: Real World Example

Since PHP already has a built-in Iterator interface, which provides convenient integration with foreach loops, it is very easy to create your own iterators for traversing almost every imaginable data structure.

This example of the Iterator pattern provides easy access to CSV files.