下面我有一段代码,它结合了每个问题的每个答案:
// $questionNumber is simply n in value[n][]
// $answers is an array of value attributes from <input>s for this question
foreach ($_POST['value'] as $questionNumber => $answers) {
// combine all the answers into a single string (e.g. ACE)
$selected_answer = implode('', $answers);
// continue onto inserting rows into the Answer and Questions tables
// ...
}
例如:
Question 1: Answer: ACE
Question 2: Answer: BD
Question 3: Answer: C
但我实际上想分开答案,以便它显示如下:
Question 1: Answer: A
Question 1: Answer: C
Question 1: Answer: E
Question 2: Answer: B
Question 2: Answer: D
Question 3: Answer: C
那么我的问题是,我需要在我的 php 中进行哪些更改以便将它们分开?
是不是应该像下面这样:
// $questionNumber is simply n in value[n][]
// $answers is an array of value attributes from <input>s for this question
foreach ($_POST['value'] as $questionNumber => $answers) {
// combine all the answers into a single string (e.g. ACE)
$selected_answer = $answers;
// continue onto inserting rows into the Answer and Questions tables
// ...
}