Iterator
T-Regx uses vanilla PHP \Iterator
with standard methods:
current()
key(): scalar
next(): void
rewind(): void
valid(): bool
#
Iterator to arrayMethod match()->getIterator()
returns an implementation of PHP \Iterator
which you can be used with other \Iterator
methods or within your own code, for example PHP methods iterator_to_array()
and iterator_count()
.
It is useful with methods that only accept \Iterator
, and when an explicit iterator is needed. Using match()->getIterator()
for methods that accept array
is redundant :)
Also, please keep in mind that match()
and other entities (such as match()->group(string|int)
or match()->asInt()
)
are also iterable with foreach
, making explicit usage of getIterator()
even less likely.