items = array_values($items); } public function current() { return $this->items[$this->i]; } public function key() { return $this->i; } public function next() { $this->i++; } public function rewind() { $this->i = 0; } public function valid() { // count() indicates how many items are in the list return $this->i < count($this->items); } } // A function that uses iterables function printIterable(iterable $displayTable) { foreach($displayTable as $item) { echo $item; } } // Use the iterator as an iterable $iterator = new SampleIterator(["1", "2", "3", "4","5"]); printIterable($iterator); ?>
12345