PHP
  Home arrow PHP arrow Iterators in the Simplest Sense: Trave...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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: 4 stars4 stars4 stars4 stars4 stars / 6
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · This last tutorial of the series shows how to apply the Iterator pattern in PHP 5,...
       · The idea is great! I couldn't get it to work, however. Seems like the problem lies...
       · Thank you for reading and commenting on this PHP article. With reference to the...
     

       

    PHP ARTICLES

    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...
    - Protecting PHP 5 Class Data with Member Visi...
    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway