1<?php
2class TestIterator implements Iterator
3{
4    protected $array;
5    protected $position = 0;
6
7    public function __construct($array = [])
8    {
9        $this->array = $array;
10    }
11
12    public function rewind()
13    {
14        $this->position = 0;
15    }
16
17    public function valid()
18    {
19        return $this->position < count($this->array);
20    }
21
22    public function key()
23    {
24        return $this->position;
25    }
26
27    public function current()
28    {
29        return $this->array[$this->position];
30    }
31
32    public function next()
33    {
34        $this->position++;
35    }
36}
37