0

基本しか理解していないので、forループに慣れようとしています。以下のコードを単純化しようとしています

                    $round1 = $max / 2;
                    $round2 = $round1 + ($max / 2 / 2);
                    $round3 = $round2 + ($max / 2 / 2 / 2);
                    $round4 = $round3 + ($max / 2 / 2 / 2 / 2);
                    $round5 ...

これとともに:-

                    $round = array($max/2);

                    for ($i=1;$i<$max;$i++) {
                        $round[] = $round[$i -1] + $max/pow(2, $i + 1);
                    }   

そして次のコード:-

                    if($matchno <= $round[0]) {
                        $scores_round1.= '['.$score1.', '.$score2.'],'; 
                    }
                    if($matchno > $round[0] AND $matchno <= $round[1]) {
                        $scores_round2.= '['.$score1.', '.$score2.'],'; 
                    }       
                    if($matchno > $round[1] AND $matchno <= $round[2]) {
                        $scores_round3.= '['.$score1.', '.$score2.'],'; 
                    }
                    if($matchno > $round[2] AND $matchno <= $round[3]) {
                        $scores_round4.= '['.$score1.', '.$score2.'],'; 
                    }

if() の使用を避けるために、上記を for ループで使用できますか?

手伝ってくれてありがとう

4

3 に答える 3

1

round1 と残りを確認できます。

 for ($i=1;$i<$max;$i++) {
         if($matchno>$round[$i] AND $matchno <= $round[$i+1])
            ${'scores_round'.$i}.='['.$score1.', '.$score2.'],'; 
     }
于 2013-08-13T12:53:33.893 に答える
0
for($i=0;$i< count($round); $i++){
    if($match < $round[$i]){
        ${"scores_round".$i}.= '['.$score1.', '.$score2.'],';
        break;
        }
}
于 2013-08-13T13:00:41.260 に答える