SPL Iterator Helper Functions

Introduction

These PHP 5.1 functions are to help handle Iterators.

There is no current information on the speed benchmarks of these functions compared to userland functions. These functions are C implementations, so one could assume they would be quicker.

Iterator Count

Counts the elements in any Iterator. Clones the Countable interface functionality for Iterators that don’t implement Countable.

$array = array('key1' => 'value1', 'key2' => 'value2');

echo iterator_count(new ArrayIterator($array));

Iterator To Array

Copies an Iterator to an array.

$array = array('key1' => 'value1', 'key2' => 'value2');

$newarray = iterator_to_array(new ArrayIterator($array));

Possibly Related Posts:


Comments are closed.