What is the purpose of the php iterator?

searched the use of php iterator on the Internet for a day, several books are copy and paste, I hope php can answer, it is best to give the use of the scene, thank you very much!

Php
May.25,2021
The essence of the use of

iterators is to save memory overhead and improve performance.
columns such as pdo iterate over the query.
so traversing the pdo query result set has little memory overhead. But if you use a regular query, it may prompt you to exceed the memory capacity


for example, if you want to encapsulate an array class and implement an iterator, you can iterate like a native array in a loop statement. The same idea can be extended to any type that can be iterated.


can also be used to implement cooperative multi-task scheduling of php. For more information, please see
using cooperative programs to achieve multi-task scheduling in PHP

.
Menu