0
我在試圖弄清楚如何獲取用於switch語句的單選按鈕的值時遇到了困難。基本上,當用戶選擇其中一個單選按鈕時,我希望執行該單選按鈕的操作。不知道我是否正確設置了這個。我自己學習PHP,不知道這是否是正確的方法。以下是HTML和PHP。獲取用於在PHP中的switch語句中使用的單選按鈕值
<input class="radio" type="radio" name="calculate" value="average" checked="checked">Average<br />
<input class="radio" type="radio" name="calculate" value="total">Total<br />
<input class="radio" type="radio" name="calculate" value="both">Both<br />
這裏是PHP
$calculate_type = $_POST['calculate'];
switch ($calculate_type) {
case '$calculate_type == "average"':
$score_average = $score_total/count($scores);
break;
case '$calculate_type == "total"':
$score_total = $scores[0] + $scores[1] + $scores[2];
break;
case '$calculate_type == "both"':
$score_average = $score_total/count($scores);
$score_total = $scores[0] + $scores[1] + $scores[2];
break;
}
嘗試:'$的情況下= calculate_type =「平均」:'刪除引號 –