class demo {
private $_current = 0;
private $_next = 1;
protected function _getNext() {
$value = $this->_current + $this->_next;
$this->_current = $this->_next;
$this->_next = $value;
return $value;
}
public function getString($max) {
if($max < 1) return '';
$str = '';
while($next = $this->_getNext()) {
if ($next <= $max) {
$str .= ', ' . $next;
} else {
break;
}
}
return substr($str, 1);
}
}
不過這東西需要用對象這麽麻煩嗎...如果是老師教的...這水平...完全沒有實用價值