php中如何正确使用switch函数 [英] how to properly use switch function in php
本文介绍了php中如何正确使用switch函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想对单选按钮的值使用开关功能,但我不知道如何正确使用它.
i want to use switch function on value of radio button but i don't know how to proper use it.
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';
}
我对字符串部分的错误:) 但它不检查品牌名称是否已设置或为空.
my bad on the string part :) but it doesn't check if brandname is set or null.
推荐答案
问题是你的字符串不在引号内,例如:case Miscellaneous: should be case "Miscellaneous":
problem is that your strings aren't inside quotes ex : case Miscellaneous: should be case "Miscellaneous":
这篇关于php中如何正确使用switch函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文