Skip to content

Instantly share code, notes, and snippets.

@tournasdim
Created February 22, 2014 08:22
Show Gist options
  • Save tournasdim/9150448 to your computer and use it in GitHub Desktop.
Save tournasdim/9150448 to your computer and use it in GitHub Desktop.
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 />';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment