News Feed
Sections




News Archive
feed this:

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

Anthony Ferrara:
Iterators - Programming With Anthony
January 17, 2013 @ 10:38:45

Anthony Ferrara is back again with another installment in his "Programming with Anthony" video series. In this new episode he takes a loot at iterators in PHP and how they can be used effectively.

Today's Programming With Anthony video focuses on the concept of Iterators. We'll look at the abstraction that they represent, how they can be used and some of the benefits of using them. When used correctly, Iterators can lead to very efficient, flexible and clean code.

You can also watch the video directly on YouTube and check out the rest of the series in his playlist. Other topics include dependency injection, boolean logic and prepared statements.

0 comments voice your opinion now!
video tutorial programming iterators series


PHPMaster.com:
Using SPL Iterators, Part 2
May 22, 2012 @ 08:23:17

On PHPMaster.com today they've posted the second part of the series covering the Iterators that come with PHP as a part of the SPL.

In part one of this series I introduced you to some of the SPL Iterators and how to use them. There may be times however when the provided iterators are insufficient for your needs and you'll want to roll your own custom iterator. Luckily, SPL provides interfaces that will allow you to do just that. For an object to be traversable in a foreach loop, PHP requires that it be an instance of Traversable. You cannot however implement this interface directly (though you can use it in instaceof checks); instead you'll need to implement either SPL's Iterator or IteratorAggregate interfaces.

He shows you how to implement these two interfaces in your own custom classes, looping through a set of books for the Iterator example and a "getIterator" method that creates an ArrayIterator when executed. The results of both are used in foreach loops showing how they can be used just like any other iteratable variables.

0 comments voice your opinion now!
spl iterators tutorial array iterator iteratoraggregate foreach


PHPMaster.com:
Using SPL Iterators, Part 1
May 15, 2012 @ 12:26:59

On PHPMaster.com today there's a new tutorial posted, the first part of a series, looking at the use of the Standard PHP Library (SPL) in PHP. In this first part of the series, Stefan Froelich looks specifically at two of the more common uses for iterators - working with arrays and directories.

When I first came across the term iteration and saw the overwhelming list of classes related to it in the SPL, I was taken aback. It seemed maybe iteration was too complex for me to grasp. I soon realized it was just a fancy word for something we programmers do all the time. [...] In the first part of this two-part series I'll introduce you to iteration and how you can take advantage of some of the built-in classes from the Standard PHP Library (SPL).

Included in the tutorial is example code showing how to use the ArrayIterator to work with an array and the DirectoryIterator to process the contents of a directory. He also briefly touches on a few other iterators like "FileExtensionFilter", "RecursiveDirectoryIterator" and "RecursiveArrayIterator".

0 comments voice your opinion now!
spl iterators tutorial array directory file recursive


PHPImpact Blog:
5 great articles on SPL Iterators
August 07, 2008 @ 09:35:03

On the PHP::Impact blog today Federico points out five articles that can help you learn more about the Standard PHP Library, specifically in dealing with iterators.

When PHP 5 was initially released, it included a strong sense of standardization introduced in the core package. This can be a real time saver when common programming issues must be solved through proven, standard solutions. That's precisely the case with iterators, since the SPL package includes many predefined iterating classes that can be used for traversing different data structures, without having to reinvent the wheel over and over again.

The links include this article on phpro.org and this one on Zend's own site.

0 comments voice your opinion now!
spl iterators link resource tutorial php5


DevShed:
Iterators in the Simplest Sense - Traversing Different Data Structures
March 15, 2006 @ 12:50:40

DevShed has posted the second part in their "Iterators in the Simplest Sense" series - this time focusing on traversing different data structures.

Welcome to the second tutorial of the series "Iterators in the simplest sense." Just in case you didn't know, this series introduces Iterators in PHP 4 - PHP 5, explaining their basic concepts, and teaches you how to use them in practical projects, which can be utilized as part of larger PHP applications.

By the end of this tutorial, I hope you'll have an accurate idea of how to use a generic Iterator structure. I will show how it is useful for traversing different data structures by providing specific implementations for each of the abstract methods defined within the base Iterator class.

They look first at extending the code that they had before by making an interator to work with a MySQL connection. They discuss how it will all work prior to coding (plan first, code later) before moving into the actual coding process and creating the class. The iterator, once extended, provides an interface between you and the normal MySQL functions, making it easier to handle the results from your queries (with things like "countAffectedRows" and "seekRow").

0 comments voice your opinion now!
iterators data structures files mysql iterators data structures files mysql



Community Events





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


introduction language library install interview laravel api wordpress bugfix threedevsandamaybe release configure community series list podcast developer application symfony code

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