PHP Switch 語句

來源:互聯網
上載者:User

PHP Switch  語句

switch語句在PHP是用來執行一個幾種不同的基礎上採取的行動之一,幾種不同的條件。

switch語句
如果你想選擇一個許多區塊的代碼將被處決,使用交換器發言。

switch語句是用來避免長期塊,如果.. elseif的..別人的代碼。

文法

 switch (expression)
{
case label1:
  code to be executed if expression = label1;
  break; 
case label2:
  code to be executed if expression = label2;
  break;
default:
  code to be executed
  if expression is different
  from both label1 and label2;
}

例如
這是如何運作:

單一的表達(最常見的一個變數)是評價一次
的價值相比,表達的價值觀為每一個案例中的結構
如果有一場比賽,代碼與該案例的執行
經過代碼執行,打破是用來阻止代碼從運行到下一個案例
預設的聲明是如果沒有使用的情況下是真正的

<html><body>
<?phpswitch ($x){case 1:  echo "Number 1";  break;case 2:  echo "Number 2";  break;case 3:  echo "Number 3";  break;default:  echo "No number between 1 and 3";}?>
</body></html>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.