Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

StarTutorial.com:
Modern PHP Developer - Iterator
Oct 16, 2018 @ 17:08:16

StarTutorial has continued their "Modern PHP Developer" series of tutorials with their latest covering the use of Iterators for working with sets of data.

If you have used a for loop in PHP, the idea of iteration is most likely not foreign to you. You pass an array to a for loop, and perform some logic inside the loop, but did you know that you can actually pass data structures other than arrays to a for loop? That's where Iterator comes into play.

The tutorial starts by introducing some of the basic concepts of what iterators are and how they're represented in PHP in their most basic form: arrays. They cover some of the basic array handing and functions before getting into the actual Iterator object handling. The article is then broken up into a few parts covering iterators and their functionality:

  • Your first iterator class
  • Why iterator?
  • SPL Iterators
  • ArrayObject vs SPL ArrayIterator
  • Iterating the File System
  • Peeking ahead with CachingIterator
  • Generator

Code and a summary of the functionality is included in each section providing you with a great start towards using iterators over simple arrays in your modern PHP applications.

tagged: developer tutorial introduction modern iterator

Link: https://www.startutorial.com/articles/view/modern-php-developer-iterator


Trending Topics: