下面分别是用迭代器实现斐波那契数列和用递归回调实现的代码
<?php
class fibonacci implements Iterator{
private $key=0;
private $value=array(0=>0,1=>1);
public function __construct(){
$this->key=0;
}
public function rewind(){
$this->key++;
}
public function key(){
return $this->key;
}
public function current(){
return $this->value[$this->key];
}
public function next(){
$this->value[++$this->key]=$this->value[$this->key-2]+$this->value[$this->key-1];
return true;
}
public function valid(){
return isset($this->value[$this->key]);
}
}
$sta