企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[TOC] ## 实例 ``` class demo implements Iterator { public $a=[1,2,3,4]; public $index=0; public function current(){ return $this->index; } public function next(){ $this->index++; return $this->a[$this->index]; } public function key(){ return $this->index; } public function valid(){ return isset($this->a[$this->index]); } public function rewind(){ return $this->index=0; } } $demo =new demo(); // 使用 foreach //foreach ($demo as $k=>$v){ // var_dump($v); //} // 使用 while while($demo->valid()){ var_dump($demo->current()); $demo->next(); } ```