Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何区分答案_Php - Fatal编程技术网

Php 如何区分答案

Php 如何区分答案,php,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

下面我有一段代码,它结合了每个问题的每个答案:

// $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: A
Question 1: Answer: C
Question 1: Answer: E
Question 2: Answer: B
Question 2: Answer: D
Question 3: Answer: C
// $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
    // ...
}
所以我的问题是,我需要在我的php中做什么更改,以便将它们分开

假设它如下所示:

Question 1: Answer: A
Question 1: Answer: C
Question 1: Answer: E
Question 2: Answer: B
Question 2: Answer: D
Question 3: Answer: C
// $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
    // ...
}
/$questionNumber的值仅为n[n][]
//$answers是用于此问题的s的值属性数组
foreach($_POST['value']作为$questionNumber=>$answers){
//将所有答案组合成一个字符串(例如ACE)
$selected_answer=$answers;
//继续在答案和问题表中插入行
// ...
}
试试这个:

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

    }
}

似乎循环中的循环将输出您想要的内容。如果您需要进一步的帮助,请在$\u POST上运行print\u r(),然后给我答案。

我可以简单地执行
$selected\u answer=$a