多个单独的 Switch 语句

发布于 2024-07-13 06:41:06 字数 312 浏览 6 评论 0原文

我在其中一个页面上有多个 switch 语句,以便将不同的变量以及不同的大小写传递给 URL。 我需要这些不同的 switch 语句,因为我需要不同的变量。

但是,当我在其中一个 switch 语句中放置“默认值”时,该默认值适用于所有其他 switch 语句,因此当我在 URL 中使用另一个 switch 语句的变量时,该其他 switch 语句的默认情况将出现在screen 以及此 switch 语句的情况。

我的所有 switch 语句都有一个或多个案例,我真的不知道如何解决这个问题。 请有人帮助我吗?

提前致谢, 卡勒姆。

I have multiple switch statements in on one of the pages in order to pass different variables to the URL, as well as different case. I need these different switch statements because I need the different variables.

However, when I put a "default" in one of the switch statements, that default applies to every other switch statement and so when I use the variable of another switch statement in the URL, the default case of that other switch statement will appear on screen, along with the case of this switch statement.

All of my switch statements have one or more cases and I really cannot figure out how to get around this. Please may somebody help me?

Thanks in advance,
Calum.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生寂 2024-07-20 06:41:06

这可能有点遥远,但我认为你需要这样的东西:

if (isset($_POST['myvar'])) {
   switch ($_POST['myvar'] {
      case 1:
      ....
      break;
      default:
      ....
      break;
   }
} else if (isset($_POST['myvar2'])) {
   switch ($_POST['myvar2'] {
      case 1:
      ....
      break;
      default:
      ....
      break;
   }
}

这有意义吗?

This might be way off, but I think you need something like this:

if (isset($_POST['myvar'])) {
   switch ($_POST['myvar'] {
      case 1:
      ....
      break;
      default:
      ....
      break;
   }
} else if (isset($_POST['myvar2'])) {
   switch ($_POST['myvar2'] {
      case 1:
      ....
      break;
      default:
      ....
      break;
   }
}

Does that make sense?

紫罗兰の梦幻 2024-07-20 06:41:06

确保你有一个“休息时间”; 在每个案例末尾声明,默认案例是最后一个。 像这样:

switch ($var) {
    case 1: // do stuff 1;
            break;
    case 3: // do stuff 2;
            break;
    // ...
    default: // do default stuff
}

make sure that you have a "break;" statement at the end of each of your cases, and that the default case is the last one. like this:

switch ($var) {
    case 1: // do stuff 1;
            break;
    case 3: // do stuff 2;
            break;
    // ...
    default: // do default stuff
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文