php-如何将这个 IF 条件放入开关中?

标签 php switch-statement

<分区>

请帮我改正这段代码,我想把 if 放在 switch 里面:

switch ($urlcomecatid) {

 if ($urlcomeparentid == 1 || $urlcomeparentid == 2 || $urlcomeparentid == 3)
  break;

case "50":
case "51":
case "52":
case "109":
case "110":
    //do nothing and exit from switch
    break;
default:
    header ("Location:http://www.example.com/tech/tech.php"); exit();
    break;

}

最佳答案

正确的代码应该是这样的

switch ($urlcomecatid) {
    case "50":
    case "51":
    case "52":
    case "109":
    case "110":
        //do nothing and exit from switch
        break;
    default:
        if ($urlcomeparentid == 1 || $urlcomeparentid == 2 || $urlcomeparentid == 3)
            break;
        header ("Location:http://www.example.com/tech/tech.php"); exit();
        break;
 }

关于php-如何将这个 IF 条件放入开关中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6881396/

相关文章:

php - 比较循环中文本框的值并突出显示最小值

php - Ruby httparty 发布请求

javascript - jquery 在 switch 案例中使用范围?

javascript - 在此示例中,switch 语句是否从顶部开始比较案例?

php - 切换多个 case 语句

swift - 错误: Expression pattern of type 'CountableClosedRange<Int>' cannot match values of type 'UITextField!'

php - 服务器 A 使用 xmlreader 从服务器 B 上的 xmlwriter 读取 XML

php - MySQL PHP PDO 远程服务器

php - 了解数据库表的 JSON 输出

c - 嵌套 switch 导致无限循环