0

以下に、質問ごとに各回答を組み合わせたコードを示します。

// $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
    // ...
}
4

1 に答える 1

1

これを試して:

foreach ($_POST['value'] as $questionNumber => $answers) 
{
    foreach($answers as $a)
    {  
             echo "Question: $questionNumber Answer: $a";

    }
}

ループ内のループが必要なものを出力するようです。さらにヘルプが必要な場合は、$ _ POSTでprint_r()を実行して、答えを教えてください。

于 2012-10-11T00:04:24.900 に答える