PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

MaltBlue.com: Painless Data Traversal with PHP FilterIterators

Note: This article was originally published at PHPDeveloper on 26 October 2012.
PHPDeveloper

On the MaltBlue blog Matt Setter has a new post introducing you to using FilterIterators for data traversal:

There's load of ways to traverse data, especially in PHP where there are a variety of loops available; including while, do while, for and foreach. These are fine for normal structures, such as scalar and associative arrays. But what if you want to get a bit more fancy?

He includes a bit of code showing the typical looping approach that a lot of developers take and how, using a FilterIterator, you can extend the default and make a custom "accept" method to remove certain matching items from the data set.