//初始化前两项
$prevNum1 = 0;
$prevNum2 = 1;
//输出初始值
echo $prevNum1,"\n";
echo $prevNum2,"\n";
while(1) {
echo $prevNum1 + $prevNum2,"\n";
/**
* 根据 斐波那契数列的规则
* 从第三项开始,每一项都是前两项之和
* 所以这里重新计算一下项的前两项
*/
$tmp = $prevNum2;
$prevNum2 = $prevNum1 + $prevNum2;
$prevNum1 = $tmp;
sleep(1);
}
命令行下的代码运行结果。