2011-05-17 155 views
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 
?> 

任何人都可以发现此代码中的任何问题?PHP虽然循环是无限的

while循环不是按照它应该的那样工作,也不会输出!

感谢

+0

-1的值???为什么投票下来? – benhowdle89 2011-05-17 17:17:23

回答

2

增量currentScene

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

更改此

foreach ($scene as $somethingThatHappened) 

foreach ($scenes as $somethingThatHappened) 
1

此:

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

两个$currentScene$sceneCount不会改变。

0

的问题是在这里:

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

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