任何人都可以解释$ flipCount如何工作?

时间:2015-09-30 10:14:11

标签: php

我在理解以下递归代码时遇到一些麻烦:

  <!DOCTYPE html>
   <html>
       <head>
           <link type='text/css' rel='stylesheet' href='style.css'/>
           <title>More Coin Flips</title>
       </head>
       <body>
       <p>We will keep flipping a coin as long as the result is heads!</p>
       <?php
       $flipCount = 0;
       do {
           $flip = rand(0,1);
           $flipCount ++;
           if ($flip){
               echo "<div class=\"coin\">H</div>";
           }
           else {
               echo "<div class=\"coin\">T</div>";
           }
       } while ($flip);
       $verb = "were";
       $last = "flips";
       if ($flipCount == 1) {
           $verb = "was";
           $last = "flip";
       }
       echo "<p>There {$verb} {$flipCount} {$last}!</p>";
       ?>
       </body>enter code here
   </html>

$flipCount如何获得$flip的数量?我不明白怎么解释呢?

1 个答案:

答案 0 :(得分:0)

Euh ...因为$flipCount ++,相当于$flipCount = $flipCount +1