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

PHP如果变量2等于某个值,如何设置变量1,php,arrays,variables,if-statement,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

嗨,我正试图让一个变量在另一个变量的if语句之后设置自己,但是我无法正确地获得语法。请帮忙,这是我目前掌握的代码

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

if      $subtype == ['12m'] {$subprice = 273.78}
elseif  $subtype == ['6m']  {$subprice = 152.10}
elseif  $subtype == ('1m')  {$subprice = 30.42}
任何帮助都将不胜感激

if ($subtype == '12m')
  $subprice = 273.78;
elseif ($subtype == '6m')
  $subprice = 152.10;
elseif ($subtype == '1m')
  $subprice = 30.42;
或与声明一起:

switch ($subtype) {
  case '12m': $subprice = 273.78; break;
  case '6m' : $subprice = 152.10; break;
  case '1m' : $subprice = 30.42; break;
}
使用PHP实现以下目标:

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

switch($subtype) {
  case "12m":
    $subprice = 273.78;
    break;
  case "6m":
    $subprice = 152.10;
    break;
  case "1m":
    $subprice = 30.42;
    break;
}

@不客气。请考虑通过单击其左侧的复选框将其标记为已接受答案。
$subtype = htmlspecialchars($_POST['subtype']);

if      ($subtype == "12m") {$subprice = 273.78}
elseif  ($subtype == "6m")  {$subprice = 152.10}
elseif  ($subtype == "1m")  {$subprice = 30.42}
$subtype = htmlspecialchars($_POST['subtype']);

switch($subtype) {
  case "12m":
    $subprice = 273.78;
    break;
  case "6m":
    $subprice = 152.10;
    break;
  case "1m":
    $subprice = 30.42;
    break;
}