freeCodeCamp/guide/chinese/php/switch-statements/index.md

30 lines
552 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Switch Statements
localeTitle: 切换语句
---
## 切换语句
Switch语句根据条件的值执行代码块。
### 句法:
```PHP
switch(x) {
case 1:
statement1;
break;
case 2:
statement2;
break;
default:
defaultstatement;
}
```
在上面的例子中x是条件。将执行匹配案例之后的陈述。如果没有匹配项则将运行默认语句。
`break`关键字用于结束每个案例。
### 更多信息:
[PHP开关](http://php.net/manual/en/control-structures.switch.php)