我是PHP新手,我需要使用多维关联数组创建测验。测验像预期的那样打印出来,但我有两个问题,一个是我在尝试使单选按钮变得粘滞时遇到了麻烦。另一个问题是,我希望关键字"3“是所有问题的答案,但我似乎找不到一种方法来计算"3”被选中的次数并打印出答案。在过去的7个小时里,我尝试了很多不同的东西,但似乎都没有按我想要的方式工作。你有什么建议或建议吗?
$quiz = array(
"What does HTML stand for?" => array(
'1' => "Home Tool Markup Language",
'2' => "Hyperlinks and Text Markup Language",
'3' => "Hyper Text Markup Language",
'4' => "Hyper Text Manipulation Language",
),
"Choose the correct HTML tag for the smallest heading:" => array(
'2' => "<heading>",
'1' => "<h1>",
'4' => "<head>",
'3' => "<h6>",
),
);
foreach($quiz as $question => $answers) {
echo $question;
echo "<form>";
foreach($answers as $index => $answer) {
echo "<input type='radio' name=$option>".$answer."<br/>";
}
}
?>发布于 2017-03-06 03:44:23
修改后的代码:
$quiz = array(
"What does HTML stand for?" => array(
'1' => "Home Tool Markup Language",
'2' => "Hyperlinks and Text Markup Language",
'3' => "Hyper Text Markup Language",
'4' => "Hyper Text Manipulation Language",
),
"Choose the correct HTML tag for the smallest heading:" => array(
'2' => "<heading>",
'1' => "<h1>",
'4' => "<head>",
'3' => "<h6>",
),
);
echo "<form>";
foreach($quiz as $question => $answers) {
echo $question;
foreach($answers as $index => $answer) {
echo "<input type=\"radio\" name=\"$question\" value=\"$option\">$answer<br/>";
}
}
echo "</form>";https://stackoverflow.com/questions/42613067
复制相似问题