當前位置:編程學習大全網 - 編程軟體 - PHP運用類和對象實現斐波那契數列

PHP運用類和對象實現斐波那契數列

<?php

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);

}

}

不過這東西需要用對象這麽麻煩嗎...如果是老師教的...這水平...完全沒有實用價值

  • 上一篇:photoshop壹般用於哪個行業
  • 下一篇:用英文介紹基辛格
  • copyright 2024編程學習大全網