解析错误:语法错误,意外的T

在codeacademy上做了一些非常基本的编码,这已经让我烦恼了一个多小时。 此代码可能有错,它显示错误“ 解析错误:语法错误,第12行中出现意外的T_ELSEIF”

<html>
  <head>
    <title>Our Shop</title>
  </head>
  <body>
    <p>
      <?php
        $items = 10;    // Set this to a number greater than 5!
        if ($items > 5) {
          echo "You get a 10% discount!"; }
          else { echo "You get a 5% discount!";
          } elseif ($items == 1) {
              echo "Sorry, no discount!";
          }


      ?>
    </p>
  </body>
</html>

else块必须是最后一个。 如果出现以下情况,则无法前往else if

if ($items > 5) {
    echo "You get a 10% discount!";
} else if ($items == 1) {
    echo "Sorry, no discount!";
} else {
    echo "You get a 5% discount!";
}

如果你打算使用else if你的else块应该是最后一块。 请注意您对{}使用。 如果它很混乱,很难阅读和更难调试。

<html>
  <head>
    <title>Our Shop</title>
  </head>
  <body>
    <p>
      <?php
        $items = 10;    // Set this to a number greater than 5!
        if ($items > 5) {
            echo "You get a 10% discount!";
        } else if ($items == 1) {
            echo "Sorry, no discount!"; 
        } else { 
            echo "You get a 5% discount!";
        }
      ?>
    </p>
  </body>
</html>
链接地址: http://www.djcxy.com/p/12019.html

上一篇: Parse error: syntax error, unexpected T

下一篇: syntax error, unexpected T