gpt4 book ai didi

php - 使用 PHP 区分正确答案的选择

转载 作者:行者123 更新时间:2023-11-28 15:46:41 24 4
gpt4 key购买 nike

会有4个选项选项1,选项2,选项3,选项4

(A) Any student who does not have the power to learn in a group is almost always unsuccessful 

(B) EDPeer group pressure and mutual understanding of any concept develops better understanding among students

(C) ESAny student who does not have the power to learn in a group is almost always unsuccessful

(D) Peer group pressure and mutual understanding of any concept develops better understanding among students

$single_answer1="ESAny student who does not have the power to learn in a group is almost always unsuccessful ".

$single_answer1 是学生选择的答案。

从以上选项中,“选项 1”是正确答案,但学生选择“选项 3”。

我必须像这样区分
“选项 1”,背景为绿色
“选项 3”,背景色为红色

如果有时选项 1 和答案都相等,则将边框颜色设为绿色。

如果 single_answer 是“undefined”或空值,那么它将以黄色背景显示正确答案(未选择任何内容和正确答案)。

<?php if ($option1 == $single_answer1) { ?>
<label style="font-size:14px;background-color:lightgray;border:1px solid green;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
<span class="">(A) <?php echo $option1; ?>
</label>
<?php } else if ($single_answer1 != $option1) {
?>
<label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
<span class="">(A) <?php echo $option1; ?>
</label>
<?php } else if ($single_answer1 == 'undefined') { ?>
<label style="font-size:14px;background-color:yellow;border:1px solid green;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
<span class="">(A) <?php echo $option1; ?>
</label>
<?php } else { ?>
<label style="font-size:14px">
<span class=""><input type="radio" name="single_question_answer1" value="<?php echo $option1; ?>" ></span> (A) <?php echo $option1; ?>
</label>
<?php } ?><br/><br/>

我这样试过,但我得到了错误的输出,请任何人帮助我解决这个问题。在此先感谢。

最佳答案

首先改变你的洗牌逻辑,

$a = [$option1, $option2, $option3, $option4];
shuffle($a);
$b = ['option1', 'option2', 'option3', 'option4'];
$result = array_combine($b, $a);
extract($result);

这是你的代码,

if ($option1 == $correct_answer && $correct_answer == $single_answer1) {
$sc_flag = 1; // student's selected correct flag
}
if ($option2 == $correct_answer && $correct_answer == $single_answer1) {
$sc_flag = 2;
}
if ($option3 == $correct_answer && $correct_answer == $single_answer1) {
$sc_flag = 3;
}
if ($option4 == $correct_answer && $correct_answer == $single_answer1) {
$sc_flag = 4;
}
if ($option1 == $correct_answer) {
$correct_flag = 1; // correct answer
}
if ($option2 == $correct_answer) {
$correct_flag = 2;
}
if ($option3 == $correct_answer) {
$correct_flag = 3;
}
if ($option4 == $correct_answer) {
$correct_flag = 4;
}
if ($option1 == $single_answer1) {
$actual_flag = 1; // selected option by student
}
if ($option2 == $single_answer1) {
$actual_flag = 2;
}
if ($option3 == $single_answer1) {
$actual_flag = 3;
}
if ($option4 == $single_answer1) {
$actual_flag = 4;
}
?>
<?php if ($sc_flag == 1) {?>
<label style="font-size:14px;background-color:lightgray;border:1px solid green;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
<span class="">(A) <?php echo $option1; ?>
</label>
<?php } else if ($actual_flag == 1 && $correct_flag != 1) {
?>
<label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
<span class="">(A) <?php echo $option1; ?>
</label>
<?php } else if ($correct_flag == 1) {?>
<label style="font-size:14px;background-color:yellow;border:1px solid yellow;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:yellow;font-size:15px"></i></label>
<span class="">(A) <?php echo $option1; ?>
</label>
<?php } else {?>
<label style="font-size:14px">
<span class=""><input type="radio" name="single_question_answer1" value="<?php echo $option1; ?>" ></span> (A) <?php echo $option1; ?>
</label>
<?php }?><br/><br/>
<?php if ($sc_flag == 2) {?>
<label style="font-size:14px;background-color:lightgray;border:1px solid green;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
<span class="">(B) <?php echo $option2; ?>
</label>
<?php } else if ($actual_flag == 2 && $correct_flag != 2) {
?>
<label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
<span class="">(B) <?php echo $option2; ?>
</label>
<?php } else if ($correct_flag == 2) {?>
<label style="font-size:14px;background-color:yellow;border:1px solid yellow;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:yellow;font-size:15px"></i></label>
<span class="">(B) <?php echo $option2; ?>
</label>
<?php } else {?>
<label style="font-size:14px">
<span class=""><input type="radio" name="single_question_answer1" value="<?php echo $option2; ?>" ></span> (B) <?php echo $option2; ?>
</label>
<?php }?><br/><br/>
<?php if ($sc_flag == 3) {?>
<label style="font-size:14px;background-color:lightgray;border:1px solid green;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
<span class="">(C) <?php echo $option3; ?>
</label>
<?php } else if ($actual_flag == 3 && $correct_flag != 3) {
?>
<label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
<span class="">(C) <?php echo $option3; ?>
</label>
<?php } else if ($correct_flag == 3) {?>
<label style="font-size:14px;background-color:yellow;border:1px solid green;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
<span class="">(C) <?php echo $option3; ?>
</label>
<?php } else {?>
<label style="font-size:14px">
<span class=""><input type="radio" name="single_question_answer1" value="<?php echo $option3; ?>" ></span> (C) <?php echo $option3; ?>
</label>
<?php }?><br/><br/>
<?php if ($sc_flag == 4) {?>
<label style="font-size:14px;background-color:lightgray;border:1px solid green;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
<span class="">(D) <?php echo $option4; ?>
</label>
<?php } else if ($actual_flag == 4 && $correct_flag != 4) {
?>
<label style="font-size:14px;background-color:lightgray;border:1px solid red;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-times" style="color:red;font-size:15px"></i></label>
<span class="">(D) <?php echo $option4; ?>
</label>
<?php } else if ($correct_flag == 4) {?>
<label style="font-size:14px;background-color:yellow;border:1px solid green;padding:10px" >
<label class="review-icon"><i class="fa fa-fw fa-check-circle-o" style="color:green;font-size:15px"></i></label>
<span class="">(D) <?php echo $option4; ?>
</label>
<?php } else {?>
<label style="font-size:14px">
<span class=""><input type="radio" name="single_question_answer1" value="<?php echo $option4; ?>" ></span> (D) <?php echo $option4; ?>
</label>
<?php }?><br/><br/>

关于php - 使用 PHP 区分正确答案的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42580455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com