pos=0;}#定义valid 方法public function valid(){#判断是">
当前位置:Gxlcms > PHP教程 > php手册学习的迭代器Iterator

php手册学习的迭代器Iterator

时间:2021-07-01 10:21:17 帮助过:4人阅读

pos = 0;
	}

	#定义指针置0 rewind
	public function rewind(){
		echo __METHOD__,"
"; $this->pos=0; } #定义valid 方法 public function valid(){ #判断是否可行 echo __METHOD__,"
"; if(isset($this->arr[$this->pos])){ return isset($this->arr[$this->pos]); } } #获取当前的值 current public function current(){ echo __METHOD__,"
"; return $this->arr[$this->pos]; } #获取当前的键值 key public function key(){ echo __METHOD__,"
"; return $this->pos; } #指针下移函数 public function next(){ echo __METHOD__,"
"; ++$this->pos; } } #实例化对象 $test = new MyIterator(); #遍历对象 foreach($test as $key=>$val){ var_dump($key,$val); echo '
'; }

以上就介绍了php手册学习的 迭代器 Iterator,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行