2013-07-06 157 views
0

我有這兩個代碼應該做同樣的事情,但回聲是完全不同的,我不知道爲什麼。 1RST代碼while循環裏面for循環沒有顯示所有結果,但只有1

<?php 
    $runs = 10000; 

    $start = microtime(true); 
    for ($x = 0; $x < $runs; $x++) { 
     for($i=1;$i<1001;$i++) echo $i%15?$i%5?$i%3?$i:'koukou':'roukou':'koukouroukou'," "; 
    } 
    $end = microtime(true); 
    $elapsed = number_format($end - $start, 4); 
    $one = number_format(($end - $start)/500, 7); 
    echo "$runs runs in $elapsed seconds, average of $one seconds per call"; 
?> 

第二碼

<?php 
    $runs = 10000; 

    $start = microtime(true); 
    for ($x = 0; $x < $runs; $x++) { 
     while(++$i<1001)echo$i%15?$i%5?$i%3?$i:'koukou':'roukou':'koukouroukou'," "; 
    } 
    $end = microtime(true); 
    $elapsed = number_format($end - $start, 4); 
    $one = number_format(($end - $start)/500, 7); 
    echo "$runs runs in $elapsed seconds, average of $one seconds per call"; 
?> 

爲什麼我得到不同的結果回聲?

+0

擁有與空白呢?這是我看到的唯一區別 – elclanrs

+0

'echo $ i' - >'echo $ i' – mishik

+3

我沒有在第二種情況下初始化 – mnagel

回答

0
for ($x = 0; $x < $runs; $x++) { 
     while(++$i<1001)echo$i%15?$i%5?$i%3?$i:'koukou':'roukou':'koukouroukou'," "; 
} 

應該

for ($x = 0; $x < $runs; $x++) { 
    $i=0; 
     while(++$i<1001)echo$i%15?$i%5?$i%3?$i:'koukou':'roukou':'koukouroukou'," "; 
} 
+0

謝謝...那是我的錯誤...該死的...再次感謝 – akman