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

Hakre's Blog:
Iterating over Multiple Iterators at Once
Apr 16, 2012 @ 17:09:44

In a recent post to his blog Hakre looks at iterating over iterators (multiples all at once) using either the Append Iterator or the MultipleIterator.

PHP’s SPL has two build-in Iterators that deal with multiple iterators at once: AppendIterator and MultipleIterator. In this posting I’ll cover both a bit.

He gives some sample code for each - showing how to use the AppendIterator to combine multiple iterators into one set and using the MultipleIterator to attach (not append/merge into one set) multiple iterator objects to a single, iteratable object. He als mentions a "lost" iterator, the DualIterator that never made it out of a SVN repository and into the main codebase.

tagged: iterating multiple simultaneous appenditerator multipleiterator tutorial

Link:

PHPro.org:
SPL AppendIterator
Dec 17, 2008 @ 17:19:32

On the PHPro.org website Kevin Waterson has posted a look at the AppendIterator iterator, a part of the SPL (Standard PHP Library) that is included with PHP5.

The SPL AppendIterator provides a method of iterating over multiple arrays at the same time. This can be very useful when aggregating data from different sources, such as XML or RSS feeds or even multiple database sources. The flexibility and efficiency of the whole SPL suite of tools is a the disposal of the AppendIterator making manipulating data in multiple objects fast and simple with a minimum of code.

His example shows what an AppendIterator object looks like, how to use it to add new values to an array and how to filter values out of the append process with a FilterIterator object.

tagged: tutorial spl appenditerator filteriterator filter array

Link:


Trending Topics: