2011-05-17 208 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++移動到下一個值。