php 中的多个 case 或 switch 命令?
下午好,
我正在尝试将一些变量分配给具有主类别和子类别的列表。这对于大多数变量都适用,但是在每个子类别中都有一些不同的字段。
IE 主类别1有子类别数据库、开发和其他 主类别 2 有子类别电子邮件、互联网和其他 主类别3有子类别图形和其他。
所以我的第一个案例陈述如下,效果很好。
switch ($main_cat)
{
case "Main Category 1":
$main="79";
break;
case "Main Category 2":
$main="83";
break;
case "Main Category 3":
$main="87";
break;
}
然而,我正在为如何处理其他问题而苦苦挣扎。
这会停止整个页面加载,并且不会出现错误消息
switch ($second_cat)
{
case "Database":
$second="145";
break;
case "Development":
$second="146";
break;
case "Other":
if ($main_cat) == 'Main Category 1' { $second="147";}
break;
}
这根本不起作用,第二个没有改变。
switch ($second_cat)
{
case "Database":
$second="145";
break;
case "Development":
$second="146";
break;
case "Other":
switch ($main_cat)
{
case "Main Category 1":
$second="147";
break;
}
}
Good Afternoon,
I am trying to assign some variables to a listing which has a main category and a subcategory. This works fine for most of the variables, however in each sub category there are some fields which are other.
ie
Main Category 1 has sub category database, development and other
Main Category 2 has sub category email, internet and other
Main Category 3 has sub category graphics and other.
So my first case statement is as follows which works fine.
switch ($main_cat)
{
case "Main Category 1":
$main="79";
break;
case "Main Category 2":
$main="83";
break;
case "Main Category 3":
$main="87";
break;
}
However I am struggling as to how to handle other.
This stops the whole page loading with no error message
switch ($second_cat)
{
case "Database":
$second="145";
break;
case "Development":
$second="146";
break;
case "Other":
if ($main_cat) == 'Main Category 1' { $second="147";}
break;
}
This doesn't work at all, second is not changed.
switch ($second_cat)
{
case "Database":
$second="145";
break;
case "Development":
$second="146";
break;
case "Other":
switch ($main_cat)
{
case "Main Category 1":
$second="147";
break;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
格式错误的 if 语句:
应该是:
另外,您应该将
error_reporting(E_ALL);
放在脚本顶部以进行调试。Badly formed if statement:
should be:
Also, you should put
error_reporting(E_ALL);
at the top of your script for debugging purposes.