继承我的代码,我想拥有它,如果未检查无验证或验证,那么用户必须“选择购买选项”...我的方式下面的工作方式但只有一个更简单的方法如果声明?
if ($buyoption == "With Validation") {
} else if ($buyoption == "No Validation") {
} else {
$buyoptionError = "Please select a buy option";
echo "$buyoptionError <br>";
$YesorNo = 0;
}
答案 0 :(得分:1)
优化
if ($buyoption != 'With Validation' && $buyoption != "No Validation") {
$buyoptionError = "Please select a buy option";
echo "$buyoptionError <br>";
$YesorNo = 0;
}
答案 1 :(得分:0)
可能是你可以使用这个
if (((trim($buyoption) === "With Validation") || (trim($buyoption) === "No Validation")))===false) {
$buyoptionError = "Please select a buy option";
echo "$buyoptionError <br>";
$YesorNo = 0;}else{
// your code
}
答案 2 :(得分:0)
您也可以使用开关:
switch($buyoption){
case "With Validation":
#code
break;
case "No Validation":
#code
break;
default:
$buyoptionError = "Please select a buy option";
echo "$buyoptionError <br>";
$YesorNo = 0;
}
答案 3 :(得分:0)
echo ($YesorNo = ($buyoption == "With Validation" || $buyoption == "No Validation")) ? "": "Please select a buyoption";