News Feed
Sections




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

SitePoint PHP Blog:
Simple Object Iterators in PHP
April 28, 2011 @ 12:15:10

On the SitePoint PHP blog today there's a new post from Craig Buckler looking (quickly) at a handy feature of the Standard PHP Library (SPL) that can help make working with objects and arrays simpler - object iterators.

If you've been coding in PHP for a while, you may be familiar with the foreach loop. It provides an easy way to analyze every item in an array. As well as arrays, it's also possible loop through an object. If your object contains a collection of items, you can use a foreach loop to iterate over each of them. [...] Iterators is a subject which strikes fear into the heart of many developers. They sound complex and are often explained with indecipherable abstract references.

To help combat this impression, he gives a bit more practical example - turning a regular array into an ArrayIterator and looping through the collection as an object instead of just a variable. This helps to keep things contained.

0 comments voice your opinion now!
object iterator array spl tutorial


blog comments powered by Disqus

Similar Posts

NetTuts.com: Working With Controllers in Symfony 2

YoungCoders.com: The PHP Construct You've Never Used

Zend Developer Zone: Zend_Acl / Zend_Auth example scenario

Emran Hasan's Blog: Quick start on new Facebook PHP SDK (IFrame based)

Cal Evan's Blog: Three Lists I Never Want to See Again


Community Events





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


deployment zendserver code framework laravel list tips voicesoftheelephpant introduction bugfix language interview conference threedevsandamaybe api release podcast community series development

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