Skip to content

Instantly share code, notes, and snippets.

@jeremeamia
Created August 8, 2014 18:57
Show Gist options
  • Select an option

  • Save jeremeamia/33fb8c543c3ba1458059 to your computer and use it in GitHub Desktop.

Select an option

Save jeremeamia/33fb8c543c3ba1458059 to your computer and use it in GitHub Desktop.
Some iterators need to be rewound and some don't
<?php
$iter1 = new LimitIterator(new ArrayIterator(range('a', 'z')), 0, 5);
var_dump($iter1->valid(), $iter1->key(), $iter1->current());
#> bool(false)
#> NULL
#> NULL
$iter2 = new MultipleIterator();
$iter2->attachIterator(new ArrayIterator(range('a', 'z')));
var_dump($iter2->valid(), $iter2->key(), $iter2->current());
#> bool(true)
#> array(1) {
#> [0] =>
#> int(0)
#> }
#> array(1) {
#> [0] =>
#> string(1) "a"
#> }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment