Skip to content

Instantly share code, notes, and snippets.

@jeremeamia
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save jeremeamia/6ab49df836bc8e59262b to your computer and use it in GitHub Desktop.

Select an option

Save jeremeamia/6ab49df836bc8e59262b to your computer and use it in GitHub Desktop.
Demonstrates that the IteratorIterator must be rewound before it is valid.
<?php
$iter = new IteratorIterator(new ArrayIterator(range('a', 'z')));
var_dump($iter->valid(), $iter->key(), $iter->current());
#> bool(false)
#> NULL
#> NULL
$iter->rewind();
var_dump($iter->valid(), $iter->key(), $iter->current());
#> bool(true)
#> int(0)
#> string(1) "a"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment