PHP while 循环是无限的

发布于 2024-11-08 00:05:50 字数 719 浏览 0 评论 0原文

<?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 循环没有按应有的方式运行,并且没有任何输出!

谢谢

<?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
?>

Can anyone spot any problems in this code?

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

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

↘人皮目录ツ 2024-11-15 00:05:50

增加 currentScene 的值

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

并将

其更改

foreach ($scene as $somethingThatHappened)

foreach ($scenes as $somethingThatHappened)

Increment the value of currentScene

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

and

Change this

foreach ($scene as $somethingThatHappened)

To

foreach ($scenes as $somethingThatHappened)
旧时模样 2024-11-15 00:05:50

这:

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

$currentScene$sceneCount 都没有改变。

This:

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

Both $currentScene and $sceneCount are not changed.

双手揣兜 2024-11-15 00:05:50

问题就在这里:

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

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

The problem is here:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文