tournasdim
2/22/2014 - 8:22 AM

SPL's LimitIterator , a simple example

SPL's LimitIterator , a simple example

$numbers = array(22, 60, 876, 95, 77);

// Initializing the Iterator
$iterator = new ArrayIterator($numbers);

// Pass the converted array to the LimitIterator
$limiter = new LimitIterator($iterator, 0 , 4);

// Loop through the LimitIterator object
foreach ($limiter as $number) {
echo $number . '<br />';
}