1 回答

TA贡献1893条经验 获得超10个赞
我希望它能解决你的问题。
$questions = [];
$i = 0;
$questionsFile = fopen(base_path('/public/questions.txt'), 'r');
while ($line = fgets($questionsFile)) {
if ($line === "\n") {
$i++;
continue;
}
if (!isset($questions['questions'][$i])){
$questions['questions'][$i] = [
'id' => rand(1596805341210, 9999999999999),
'type' => 'Multiple Choice Single Answer',
'question' => '',
'answer_options' => []
];
}
if (preg_match("/(.)+\?/", $line)) {
$questions['questions'][$i]['question'] = $line;
} else {
$answer = [
'id' => rand(1596805341210, 9999999999999),
'marks' => null,
'value' => $line,
'selected' => false,
];
if (preg_match("/(\*)(.)+/", $line)) {
$answer['marks'] = 100;
$answer['selected'] = true;
}
$questions['questions'][$i]['answer_options'][] = $answer;
}
}
fclose($questionsFile);
return $questions;
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报