0

我有这两个代码应该做同样的事情,但回声完全不同,我不知道为什么。第一个代码

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

为什么我得到不同的回声结果?

4

1 回答 1

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'," ";
 }
于 2013-07-06T09:34:38.430 回答