开发者

PHP while loop is infinite

<?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
$scen开发者_JAVA技巧eCounter =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
?>

Can anyone spot any problems in this code?

The while loop isnt acting as it should be and nothing gets outputted!

Thanks


Increment the value of currentScene

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

and

Change this

foreach ($scene as $somethingThatHappened)

To

foreach ($scenes as $somethingThatHappened)


This:

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

Both $currentScene and $sceneCount are not changed.


The problem is here:

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

add a $currentScene++ to move to the next value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜