W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
items = array_values($items); } public function current() { return $this->items[$this->pointer]; } public function key() { return $this->pointer; } public function next() { $this->pointer++; } public function rewind() { $this->pointer = 0; } public function valid() { // count() 表示列表中有多少项 return $this->pointer < count($this->items); } } // 一个使用可迭代对象的函数 function printIterable(iterable $myIterable) { foreach($myIterable as $item) { echo $item; } } // 将迭代器用作可迭代对象 $iterator = new MyIterator(["a", "b", "c"]); printIterable($iterator); ?>