Hi I'm trying to get one variable to set itself after an if statement on another variable, but I can't get the syntax right. Please help, this is the code that I've got so far.
嗨,我试图让一个变量在另一个变量的if语句后设置自己,但我无法正确使用语法。请帮忙,这是我到目前为止的代码。
$subtype = htmlspecialchars($_POST['subtype']);
if $subtype == ['12m'] {$subprice = 273.78}
elseif $subtype == ['6m'] {$subprice = 152.10}
elseif $subtype == ('1m') {$subprice = 30.42}
Any help would be greatly appreciated!
任何帮助将不胜感激!
4 个解决方案
#1
5
if ($subtype == '12m')
$subprice = 273.78;
elseif ($subtype == '6m')
$subprice = 152.10;
elseif ($subtype == '1m')
$subprice = 30.42;
Or with the switch
statement:
或者使用switch语句:
switch ($subtype) {
case '12m': $subprice = 273.78; break;
case '6m' : $subprice = 152.10; break;
case '1m' : $subprice = 30.42; break;
}
#2
2
$subtype = htmlspecialchars($_POST['subtype']);
if ($subtype == "12m") {$subprice = 273.78; }
elseif ($subtype == "6m") {$subprice = 152.10; }
elseif ($subtype == "1m") {$subprice = 30.42; }
#3
1
Use PHP switch() to achieve that:
使用PHP switch()来实现:
$subtype = htmlspecialchars($_POST['subtype']);
switch($subtype) {
case "12m":
$subprice = 273.78;
break;
case "6m":
$subprice = 152.10;
break;
case "1m":
$subprice = 30.42;
break;
}
#4
0
$subtype = htmlspecialchars($_POST['subtype']);
if ($subtype == "12m") {$subprice = 273.78}
elseif ($subtype == "6m") {$subprice = 152.10}
elseif ($subtype == "1m") {$subprice = 30.42}
#1
5
if ($subtype == '12m')
$subprice = 273.78;
elseif ($subtype == '6m')
$subprice = 152.10;
elseif ($subtype == '1m')
$subprice = 30.42;
Or with the switch
statement:
或者使用switch语句:
switch ($subtype) {
case '12m': $subprice = 273.78; break;
case '6m' : $subprice = 152.10; break;
case '1m' : $subprice = 30.42; break;
}
#2
2
$subtype = htmlspecialchars($_POST['subtype']);
if ($subtype == "12m") {$subprice = 273.78; }
elseif ($subtype == "6m") {$subprice = 152.10; }
elseif ($subtype == "1m") {$subprice = 30.42; }
#3
1
Use PHP switch() to achieve that:
使用PHP switch()来实现:
$subtype = htmlspecialchars($_POST['subtype']);
switch($subtype) {
case "12m":
$subprice = 273.78;
break;
case "6m":
$subprice = 152.10;
break;
case "1m":
$subprice = 30.42;
break;
}
#4
0
$subtype = htmlspecialchars($_POST['subtype']);
if ($subtype == "12m") {$subprice = 273.78}
elseif ($subtype == "6m") {$subprice = 152.10}
elseif ($subtype == "1m") {$subprice = 30.42}