🎉 Hooray! After 3 years of work, I've finally released the ebook on design patterns! Check it out »
Iterator

Iterator in PHP

Iterator is a behavioral design pattern that allows sequential traversal through a complex data structure without exposing its internal details.

Thanks to the Iterator, clients can go over elements of different collections in a similar fashion using a single iterator interface.

Learn more about Iterator

Usage of the pattern in PHP

Complexity:

Popularity:

Usage examples: The pattern is very common in PHP code. Many frameworks and libraries use it to provide a standard way for traversing their collections.

The PHP has a built-in Iterator interface that can be used for building custom iterators compatible with the rest of the PHP code.

Iterator in Other Languages

Design Patterns: Iterator in Java Design Patterns: Iterator in C# Design Patterns: Iterator in Python Design Patterns: Iterator in Ruby Design Patterns: Iterator in Swift Design Patterns: Iterator in TypeScript