3v4l.org

run code in 300+ PHP versions simultaneously
<?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 is_array($d) ? 'It\'s an array!' : 'Not an array'; foreach($d as $key => $value) { echo "\n$key => $value"; }

preferences:
45.34 ms | 402 KiB | 5 Q