PHP
  Home arrow PHP arrow Iterators in the Simplest Sense: Traversing Data Structures in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Iterators in the Simplest Sense: Traversing Data Structures in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2006-03-22


    Table of Contents:
  • Iterators in the Simplest Sense: Traversing Data Structures in PHP 5
  • Working with iterators in PHP 5: using some predefined SPL classes
  • Traversing text files the easy way: the brand new FileIterator class
  • Traversing database result sets: building a MySQL iterator class

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Iterators in the Simplest Sense: Traversing Data Structures in PHP 5
    ( Page 1 of 4 )

    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.

    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
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT