} $ret = do_pick($answer, NULL, $selections, $reason); if ($ret === NULL) { $stop = TRUE; } else { return $ret; } }, $choices[0], array_keys($choices[0])); if ($stop) { return $try(); } $answers = array_map(function ($answer, $key) use(&$selections, &$stop, &$reason, &$correct) { if ($stop) { return; } $ret = do_pick($answer, NULL, $selections, $reason); if ($ret === NULL) { $stop = TRUE; } else { return $ret; } }, $choices[1], array_keys($choices[1])); if ($stop) { return $try(); } $cquiz_answers["answer{$n}"] = [implode("\n", array_map("format_word", $answers))]; if ($shuffle) { shuffle($answers); } if (count($answers) !== count(vec_norm(array_unique($answers)))) { $reason = "results were not unique (" . implode(",", $results) . ")";
function do_template($temp, $db = NULL, &$pick_db = NULL, &$reason = NULL) { if ($db === NULL) { $db = defaultDB(); } if (is_string($temp)) { return $temp; } $repeats = 0; $sentence = NULL; $reason = NULL; $ignore = NULL; $reset = []; if (is_array($pick_db)) { $reset = []; foreach ($pick_db as $k => $_) { $reset[$k] = _process_value($_, $reset, $db); } } while ($repeats < 1 and $sentence === NULL) { $repeats += 1; $sentence = []; $pick_db = $reset; foreach ($temp as $k => $t) { $res = do_pick($t, $db, $pick_db, $reason); if ($res === NULL) { $reason .= " on key {$k}"; $reason .= " (picks were " . dump_pick_db($pick_db) . ")"; $sentence = NULL; break; } elseif ($res !== FALSE) { $sentence[$k] = $res; } } } if ($sentence !== NULL) { return array_values($sentence); } }