- range: documentation ( source)
<?php
class Reader extends IteratorIterator
{
private $is_first = true;
public function current()
{
$this->is_first = false;
return parent::current();
}
public function valid()
{
$res = parent::valid();
if (!$res)
$this->is_first = true;
}
public function rewind()
{
if (!$this->is_first)
return;
$this->is_first = true;
parent::rewind();
}
}
$a = new Reader(new ArrayIterator(range(1, 10)));
foreach ($a as $v) {
echo $v . PHP_EOL;
break;
}
foreach ($a as $v) {
echo $v . PHP_EOL;
break;
}
foreach ($a as $v) {
echo $v . PHP_EOL;
break;
}