- range: documentation ( source)
<?php
class Derp implements Iterator
{
protected $index;
protected $array;
public function __construct(array $input) {
$this->array = $input;
}
public function current()
{
return $this->array[$this->index];
}
public function next()
{
$this->index += 1;
}
public function key()
{
return $this->index;
}
public function valid()
{
return isset($this->array[$this->index]);
}
public function rewind()
{
$this->index = 0;
}
}
$d = new Derp(range(1,100));
echo $d instanceof Traversable ? 'It\'s an array!' : 'Not an array.';
foreach($d as $key => $value) {
echo "\n$key => $value";
}