PHP while循环是无限的

时间:2011-05-17 16:20:45

标签: php while-loop

<?php
//Set up the base vars
$sceneCount=23;
$currentScene=1;
$brainBlownCounter=0;


//Assemble the scenes
while($currentScene <= $sceneCount)
{
    $scenes[] = 'Scene '.$currentScene;
}

//Make this film special
array_reverse($scenes);

//Play
$sceneCounter =0;
foreach ($scene as $somethingThatHappened)
{
    $sceneCounter++;

    $leonardsMemory = $somethingThatHappened;

    echo ('We see '.$somethingThatHappened.'<br />');
    echo ('Your brain is now '.(($sceneCounter / count($scenes) * 100)).'% blown.<br /><br />';

    $leonardsMemory=NULL;
}


//TODO: Remember Stanley Ipkiss
?>

有人能发现此代码中的任何问题吗?

while循环不应该正常运行,没有任何输出!

由于

3 个答案:

答案 0 :(得分:2)

增加currentScene的值

while($currentScene <= $sceneCount)
{
    $scenes[] = 'Scene '.$currentScene;
    $currentScene++;
}

更改此

foreach ($scene as $somethingThatHappened)

foreach ($scenes as $somethingThatHappened)

答案 1 :(得分:1)

此:

while($currentScene <= $sceneCount)
{
    $scenes[] = 'Scene '.$currentScene;
}

$currentScene$sceneCount都不会更改。

答案 2 :(得分:0)

问题在于:

while($currentScene <= $sceneCount)
{
--->    $scenes[] = 'Scene '.$currentScene;
}

添加$currentScene++以移至下一个值。

相关问题