Home arrow PHP arrow Iterators in the Simplest Sense: Traversing Data Structures in PHP 5

Iterators in the Simplest Sense: Traversing Data Structures in PHP 5

Welcome to the final part of the series “Iterators in the Simplest Sense.” In this set of articles, you’ll learn the basic concepts of iterators in PHP 4 and PHP 5. The overall learning experience is strongly focused on the practical sense of the topic, so you can start quickly using iterators within your own PHP applications.

TABLE OF CONTENTS:
  1. Iterators in the Simplest Sense: Traversing Data Structures in PHP 5
  2. Working with iterators in PHP 5: using some predefined SPL classes
  3. Traversing text files the easy way: the brand new FileIterator class
  4. Traversing database result sets: building a MySQL iterator class
By: Alejandro Gervasio
Rating: starstarstarstarstar / 8
March 22, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

In order to remind you of some of the key concepts I explained in my previous tutorial of this series, let me mention briefly a few crucial points regarding iterators in PHP 4. As you'll probably recall, during the second article, I illustrated with a step-by-step approach how different data structures, specifically arrays, text files and MySQL result sets, can be easily traversed by the same set of methods, which were originally declared within a generic "Iterator" class, seated on top of the classes' hierarchy.

This approach allowed me to rapidly construct different iterator classes, which came in helpful for iterating over MySQL datasets and simple text files, utilizing the functionality provided by each of the methods defined within a specific array iterator class. As you hopefully learned from the hands-on examples you saw, once this class was created, building in distinct iterating classes is just a matter of deriving different subclasses from it, and specifically implementing the corresponding methods in consonance with the type of data being traversed.

Right, with reference to the content of the first two articles of this series, I think you'll have some nice material to keep you busy for long time coding iterators in PHP 4. Now, if you're one of the many developers working with PHP 5, things can be even more interesting, since PHP 5 offers native support for iterators through the SPL (Standard PHP Library).

Considering this propitious development scenario, in this last article I'll explore the implementation of PHP 5 iterators, by utilizing some of the embedded classes that integrate the powerful SPL package. Thus you can learn quickly how to include these programming structures inside your PHP applications.

After introducing the subject of this article, it's time to move forward, in order to start using iterators in PHP 5. Let's go!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: