php switch 汉字,php switch 语法

php switch 语法用于执行基于不同条件不同的行动。

-------------------------------------------------- ------------------------------

开关语句的PHP

使用switch语句来选择代码的许多组成部分之一被执行。

语法

switch (n)

{

case label1:

code to be executed if n=label1;

break;

case label2:

code to be executed if n=label2;

break;

default:

code to be executed if n is different from both label1 and label2;

}

这是它的工作原理:首先,我们有一个单一表达式n(常常是一个变量),只计算一次。该表达式的值,然后比较与结构中每个案件的价值观。如果有匹配,与该案件相关的代码就会被执行。利用休息时间,避免因进入下一个代码自动执行。默认语句用于如果没有找到匹配。

例如

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;

}

工作原理:

对表达式(通常是变量)进行一次计算

把表达式的值与结构中 case 的值进行比较

如果存在匹配,则执行与 case 关联的代码

代码执行后,break 语句阻止代码跳入下一个 case 中继续执行

如果没有 case 为真,则使用 default 语句

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值