【发布时间】:2014-03-11 23:33:35
【问题描述】:
我想在单选按钮的值上使用开关功能,但我不知道如何正确使用它。
if(isset($_POST['Itemtype']))
{
$Itemtype = $_POST["Itemtype"];
switch ($Itemtype)
{
case "Ingredient":
$Brandname = $_POST["Brandname"];
if(isset($_POST['Brandname']))
{
$try2 = "Brandname working";
}
else
{
$errormsg = 'error on branchname';
}
break;
case "Miscellaneous":
$Size = $_POST["Size"];
$Color = $_POST["Color"];
if(isset($_POST['Size']))
{
$try2 = "Misc working";
}
else
{
$errormsg = 'error on size';
break;
}
else
{
$errormsg = 'error5';
}
我的字符串部分不好 :) 但它不检查品牌名称是否设置或为空。
【问题讨论】:
-
case 'Ingredient'因为它是一个字符串 -
我应该让
case "Ingredient";吗? -
case 'Ingredient':和case 'Miscellaneous':你只需要''
标签: php switch-statement