PHP has a number of powerful interfaces, where arrayaccess and Iterator work together to make objects as flexible as arrays.
Of course, using arrayaccess with Iterator can be used to deal with arrays, but there is a better way to do this with the arrayiterator provided by SPL
The reason is:
Arrayiterator implement Arrayaccess, Seekableiterator, countable, searializable {}
The next step is to introduce a higher level of iterator usage.
Functions related to iterator are recorded first.
Iterator_to_array () Converts an element in an iterator to an array
Iteratoraggregate::getiterator () calls an external iterator
Arrayiterator
Iteartor_count () et cetera
PHP's use of the iterator interface is an implementation of the iterator pattern. Here, the conceptual client (implementing the iterative process), the iterator, and the specific iterator do not correspond to, foreach (), the concrete class that inherits from the iterator interface, and the array or collection that needs to be traversed.
The builder is better understood on top of the iterator.
To be continued .....
PHP iterators and Kazuo Generators