News Feed
Sections




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

Jake Smith's Blog:
Callback Filter Iterator in PHP 5.3/5.4
December 02, 2011 @ 08:44:34

Jake Smith has a new post to his blog today about a feature included in PHP's Standard PHP Library that you might have overlooked - the FilterIterator's callback functionality.

The Filter Iterator is probably my second favorite iterator, next to Directory Iterator. There are many great use cases for the Filter Iterator, and when you do filter the original data is left untouched. A Filter Iterator is really simple to use, create a class that extends FilterIterator and adjust the accept method to meet your criteria. This is great and all, but having the ability to create filter iterators on the fly, ones that won't be used application wide, without having to create a class is even better.

He includes a bit of code defining a FilterCallbackIterator class with a "callback" parameter passed into the constructor (in his case, a closure). Also included is some sample code of it in use - handling an array (well, ArrayIterator) with a simple true/false check on the current array value. You can find out more about this functionality in the PHP manual.

0 comments voice your opinion now!
callback filter iterator spl tutorial closure


blog comments powered by Disqus

Similar Posts

PHPBuilder.com: Developing a Ajax-driven Shopping Cart with PHP and Prototype, Part 2

The Bakery: Basic User Authentication in (CakePHP) 1.2.x

CodeIgniter Blog: CodeIgniter Community Voice - Generating PDF files using CodeIgniter

Christopher Kunz's Blog: Thoughts on ext/filter et al.

Stephan Hochdörfer: Configuring Xdebug and phpstorm for CLI debugging


Community Events

Don't see your event here?
Let us know!


application configure laravel series conference library podcast framework symfony2 language performance opinion api introduction interview release community install php7 example

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework