News Feed
Sections




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

Lorna Mitchell's Blog:
Using iterator_to_array() in PHP
February 29, 2012 @ 08:55:52

Lorna Mitchell has a new post to her blog today showing off a lesser-known but very useful function included in PHP - the iterator_to_array function, used to translate things that implement Traversable into arrays.

Someone watching over my shoulder recently had never seen the ubiquitously-useful iterator_to_array() before. [...] Mostly I find this useful when I'm working with collections of data as these often present themselves as an object that you can foreach() over, but you can't dump it directly. If the object in question implements the Traversable interface, you can instead pass it into iterator_to_array to get the data as an array.

She includes a brief snippet of code showing it in use - transforming the results from a MongoDB cursor object back into an array.

0 comments voice your opinion now!
iterator translate array snippet traversable


blog comments powered by Disqus

Similar Posts

Rob Allen's Blog: Translations of my Zend Framework Tutorial for ZF 1.10 & 1.11

Christopher Jones' Blog: Casting PL/SQL arrays as REF CURSORS for Ruby (and PHP)

Rob Young's Blog: Chunking Large Queries with Iterators in PHP

David Coallier's Blog: Translating JAWS from PHP4 to PHP6 (Woo I'm a mentor)

Lorna Mitchell's Blog: Using iterator_to_array() in PHP


Community Events

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


voicesoftheelephpant opinion php7 api library laravel5 video language laravel framework extension unittest version podcast series interview community development introduction release

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