【发布时间】:2021-06-05 16:52:02
【问题描述】:
当用户提交 from 时,我得到了 40 个键值数据。如下所示。
$student_answer = [
1 => "rehabilitation of offenders",
2 => "has been accelerating",
3 => "all expectations",
4 => "question the validity",
5 => "than alleviate",
6 => "more effective alternatives",
7 => "social and economic",
8 => "dcfgvhjk",
9 => "vghbjnk",
10 => "hbjnk",
11 => "gvhbjn",
12 => "vbhnm",
13 => "fghj",
14 => "fghj",
15 => "vghbj",
16 => "cgvhb",
17 => "vbhn",
18 => "vbn",
19 => "fghj",
20 => "gvhbj",
21 => "cvbn",
22 => "vbn",
23 => "v bn",
24 => "cfghjk",
"25-26" => [
0 => "D",
1 => "E",
],
27 => "fgvhbj",
28 => "vbnm",
29 => "v bnm",
30 => "v bnm",
31 => "n hb",
32 => "hbjnkm",
33 => "bnm",
34 => "bnm",
35 => "b nm",
36 => "b nm",
37 => "v bn",
38 => "vbnm",
"39-40" => [
0 => "A",
1 => "D",
],
];
我有正确的答案来自如下数据库:
$answer_from_database = [
1 => [
0 => "rehabilitation of offenders"
],
2 => [
0 => "has been accelerating"
],
3 => [
0 => "all expectations"
],
4 => [
0 => "question the validity"
],
5 => [
0 => "than alleviate"
],
6 => [
0 => "more effective alternatives"
],
7 => [
0 => "social and economic"
],
8 => [
0 => "NOT GIVEN"
],
9 => [
0 => "FALSE"
],
10 => [
0 => "TRUE"
],
11 => [
0 => "TRUE"
],
12 => [
0 => "FALSE"
],
13 => [
0 => "FALSE"
],
14 => [
0 => "moral or philosophical"
],
15 => [
0 => "physiological/biological disposition"
],
16 => [
0 => "heritable/inherited"
],
17 => [
0 => "characterised by"
],
18 => [
0 => "hereditary aspect/biological basis"
],
19 => [
0 => "associated with"
],
20 => [
0 => "criminal tendencies"
],
21 => [
0 => "Chromosomal abnormality"
],
22 => [
0 => "masculine and aggressive"
],
23 => [
0 => "severely undermined by"
],
24 => [
0 => "environmental and social"
],
"25-26 " => [
0 => "D",
1 => "E",
],
27 => [
0 => "means"
],
28 => [
0 => "for identification purposes"
],
29 => [
0 => "victims"
],
30 => [
0 => "centred on"
],
31 => [
0 => "removed"
],
32 => [
0 => "law enforcement agencies"
],
33 => [
0 => "evade capture"
],
34 => [
0 => "crime scene"
],
35 => [
0 => "the publication of"
],
36 => [
0 => "modern forensic techniques/forensic science"
],
37 => [
0 => "fingerprint-ing/new-found"
],
38 => [
0 => "standard practice"
],
"39-40" => [
0 => "A",
1 => "D",
]
];
现在我想检查学生的答案是否与来自数据库的答案匹配,如果答案正确,我想增加$count的值,
到目前为止,我已经这样做了:
//$data = student's answer
//$answerKey = right answer
foreach($data as $key => $student){
$count = 0;
foreach($answerKey as $rkey => $right){
if($student == implode (", ", $right)){
$count = $count + 1;
}
if(is_array($student)){
}
}
}
我卡在这里了,接下来我应该怎么做才能检查答案?
【问题讨论】:
标签: php arrays associative-array