问题描述
我有问题的数组`
I have question's array`
$questions = [
["id" => 1,"Question" => "What is the capital city of Armenia?", "Answer" => ["Yerevan", "Moscow", "New York"]],
["id" => 2,"Question" => "Who was the best footballer in 2017?", "Answer" => ["Messi", "Ronaldo", "Neymar"]],
["id" => 3,"Question" => "4 * 5 = ?", "Answer" => ["9", "45", "20"]],
["id" => 4,"Question" => "When has created PHP?", "Answer" => ["1998", "1994", "2000"]],
["id" => 5,"Question" => "Who is the president of Russia?", "Answer" => ["Lavrov", "Putin", "Medvedev"]]
];
我正在添加它身体动态。 h3标签中的问题,选择中的答案,还有我的Check按钮,点击Check按钮后必须返回真实答案的数量。
[]
我的尝试:
I'm adding it on the body dynamically. The questions in h3 tag, the answers in select, and also i have Check button, after click on Check button it must return the count of true answers.
http://prntscr.com/kpy53o[^]
What I have tried:
// quiz.php
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$name = $_POST["make"];
print $name; // in this case it prints only the last select's value
}
else{
header("location:index.php");
}
?>
<form action="quiz.php" method="post">
<?php
foreach($questions as $value){
?>
<div id="d1">
<fieldset>
<legend id="h1"><?= "Question"." ".$value["id"].":"?></legend>
<h3 class="h3"><?= $value["Question"]?></h3>
<select name="make" class="btn btn-outline-info">
<?php
for($i = 0; $i < count($value["Answer"]); $i++){ ?>
<option><?= $value["Answer"][$i]?></option>
<?php }
?></select></fieldset>
</div>
<?php
}
?>
<button id="btn1" class="btn btn-success">Check</button>
</form>
如何从每个选项中获取价值?我怎样才能检查每一个条件?
// $ count = 0;
if(option1 ==Yerevan){
count ++;
}
if(option2 ==Ronaldo){
count ++;
}
等等。如何获得option1,option2 ....?
How can i get values from every option? How can i check every condition?
// $count = 0;
if(option1 == "Yerevan"){
count++;
}
if(option2 == "Ronaldo"){
count++;
}
and so on. How to get option1, option2....?
推荐答案
我正在添加它身体动态。 h3标签中的问题,选择中的答案,还有我的Check按钮,点击Check按钮后必须返回真实答案的数量。
[]
我的尝试:
I'm adding it on the body dynamically. The questions in h3 tag, the answers in select, and also i have Check button, after click on Check button it must return the count of true answers.
http://prntscr.com/kpy53o[^]
What I have tried:
// quiz.php
<?php
if(
这篇关于Php:如何从select / option中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!