PHP如果变量2等于某个值,如何设置variable1

0 php arrays variables if-statement

嗨我试图让一个变量在另一个变量的if语句之后设置自己,但我无法正确使用语法.请帮忙,这是我到目前为止的代码.

$subtype = htmlspecialchars($_POST['subtype']);

if      $subtype == ['12m'] {$subprice = 273.78}
elseif  $subtype == ['6m']  {$subprice = 152.10}
elseif  $subtype == ('1m')  {$subprice = 30.42}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激!

Ind*_*rek 5

if ($subtype == '12m')
  $subprice = 273.78;
elseif ($subtype == '6m')
  $subprice = 152.10;
elseif ($subtype == '1m')
  $subprice = 30.42;
Run Code Online (Sandbox Code Playgroud)

或者switch声明:

switch ($subtype) {
  case '12m': $subprice = 273.78; break;
  case '6m' : $subprice = 152.10; break;
  case '1m' : $subprice = 30.42; break;
}
Run Code Online (Sandbox Code Playgroud)