@php $choiceQuestions = $questions['choice'] ?? []; $fillQuestions = $questions['fill'] ?? []; $answerQuestions = $questions['answer'] ?? []; $gradingMode = $grading ?? false; // 检查是否有数学公式处理标记,避免重复处理 $mathProcessed = false; // 检查所有题型中是否有任何题目包含 math_processed 标记 foreach ([$choiceQuestions, $fillQuestions, $answerQuestions] as $questionType) { foreach ($questionType as $q) { if (isset($q->math_processed) && $q->math_processed) { $mathProcessed = true; break 2; // 找到标记就退出两层循环 } } } // 计算填空空格数量 $countBlanks = function($text) { $count = 0; $count += preg_match_all('/_{2,}/u', $text, $m); $count += preg_match_all('/(\s*)/u', $text, $m); $count += preg_match_all('/\(\s*\)/', $text, $m); return max(1, $count); }; // 计算步骤数量 $countSteps = function($text) { $matches = []; $cnt = preg_match_all('/第\s*\d+\s*步/u', $text ?? '', $matches); return max(1, $cnt); }; $renderBoxes = function($num) { // 判卷方框放大 1.2 倍,保持单行布局 if ($num == 2) { // 两个方框时,使用右对齐布局 return '