News Feed
Sections




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

Stanislav Malyshev's Blog:
Ruby-like iterators in PHP
January 28, 2010 @ 11:21:04

In this new post to his blog Stanislav Malyshev looks at creating some Ruby-like iterators as close as they can get in PHP.

I've started playing with Ruby recently, and one of the things that got my attention in Ruby were iterators. They are different inside from regular loops but work in a similar way, and looks like people (at least ones that write tutorials and code examples) like to use them.

He saw how one of the iterators worked - iterating over a Ruby hash - and wondered how difficult it'd be to write up something comparable in PHP. He creates a simple iterator, an array class to lay on top of it and an example of it in use. The use isn't as clean as the Ruby iterator, but it works similarly. He also includes a modification that lets you use ranges for what to return.

1 comment voice your opinion now!
ruby iterator hash array


blog comments powered by Disqus

Similar Posts

Matthew Weir O'Phinney's Blog: Overloading arrays in PHP 5.2.0

Ben Scholzen's Blog: Writing powerful and easy config files with PHP-arrays

Christoph Dorn's Blog: TIP: FirePHP data volume filtering

EchoLibre Blog: Event: Josh Holmes talks PHP, Ruby & Azure

Till Klampaeckel's Blog: Zend Framework: Writing an IN-Clause with Zend_Db


Community Events





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


package install podcast release update version language symfony library composer community framework series tool introduction security laravel interview voicesoftheelephpant opinion

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