英文:
laravel controller form array value compere if same pass 1 not pass 0
问题
我尝试从控制器中的数组值中获取值并比较所有"ANSWER"和"OPTION"数组值。
示例
如果
ANSWER 0=>A 等于 OPTION=>A 通过 1
ANSWER 0=>B 等于 OPTION=>A 通过 0
这个值存储在ANSWER_STATUS列中。
控制器
public function Store_Answer(Request $request)
{
$count= $request->Question;
if ($count) {
for ($i=0; $i < count($request->Question); $i++) {
$data = new OnlineExminAnswer();
$data->ANSWER_STATUS= $request->ANSWER_STATUS; // 在这里我想要获取比较的值1或0
$data->question = $request->Question[$i];
$data->answer = $request->OPTION[$i];
$data->save();
}
}
}
我的表单数组
"Question" => array:2 [▼
0 => "YOUR NAME"
1 => "water formula in science"
]
"ANSWER" => array:2 [▼ // 这个数组包含所有正确的答案
0 => "A"
1 => "h2O"
]
"OPTION" => array:2 [▼ // 这个数组包含学生的答案
0 => "A"
1 => "CO2"
]
英文:
I'm new to laravel I was trying to get value IN controller form array value compere all "ANSWER" AND "OPTION" array value.
EXAMPLE
ANSWER AND OPTION if
ANSWER 0=>A EQUELS OPTION=>A pass 1
ANSWER 0=>B EQUELS OPTION=>A pass 0
THIS VALUE STORE IN ANSWER_STATUS COLUMANE
CONTROLLER
public function Store_Answer(Request $request)
{
$count= $request->Question;
if ($count) {
for ($i=0; $i <count($request->Question); $i++) {
$data = New OnlineExminAnswer();
$data->ANSWER_STATUS= $request->ANSWER_STATUS; // HERE I WANT TO GET VALUE OF COMPARED 1 OR 0
$data->question = $request->Question [$i];
$data->answer = $request->OPTION[$i];
$data->save();
}
}
my form array
"Question" => array:2 [▼
0 => "YOUR NAME"
1 => "water formula in science"
]
"ANSWER" => array:2 [▼ //THIS ARRAY CONTAINING ALL RIGHT ANSWER
0 => "A"
1 => "h2O"
]
"OPTION" => array:2 [▼ //THIS ARRAY STUDENTS ANSWER
0 => "A"
1 => "CO2"
]
]
答案1
得分: 1
public function Store_Answer(Request $request)
{
$count = $request->Question;
if ($count) {
for ($i = 0; $i < count($request->Question); $i++) {
if(isset($request->ANSWER[$i]) && isset($request->OPTION[$i])) {
$data = new OnlineExminAnswer();
$data->ANSWER_STATUS = $request->ANSWER[$i] == $request->OPTION[$i] ? 1 : 0;
$data->question = $request->Question[$i];
$data->answer = $request->OPTION[$i];
$data->save();
}
}
}
}
英文:
public function Store_Answer(Request $request)
{
$count = $request->Question;
if ($count) {
for ($i = 0; $i < count($request->Question); $i++) {
if(isset($request->ANSWER[$i]) && isset($request->OPTION[$i])) {
$data = new OnlineExminAnswer();
$data->ANSWER_STATUS = $request->ANSWER[$i] == $request->OPTION[$i] ? 1 : 0;
$data->question = $request->Question[$i];
$data->answer = $request->OPTION[$i];
$data->save();
}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论