如何在php中验证多维数组中的单选按钮?

如何在php中验证多维数组中的单选按钮?,php,Php,我有一个由多维数组组成的测验。我希望能够验证单选按钮,以便显示回显消息,用户必须为每个问题单击其中一个单选按钮。我的验证目前不起作用,但我不知道当单选按钮在输入中回响时如何验证它们 <form method="post" action=""> <?php $quiz = array( 'questions' => array( "1. How many different stages of belts are there? <br>", "

我有一个由多维数组组成的测验。我希望能够验证单选按钮,以便显示回显消息,用户必须为每个问题单击其中一个单选按钮。我的验证目前不起作用,但我不知道当单选按钮在输入中回响时如何验证它们

<form method="post" action="">
<?php
$quiz = array(

'questions' => array(
   "1. How many different stages of belts are there? <br>",  
   "2. What are the four basic kicks of Tae Kwon Do? <br>", 
   "3. When was Tae Kwon Do taught in America? <br>", 
   "4. What does Tae Kwon Do mean? <br>", 
   "5. Where did Tae Kwon Do originate? <br>",
   ), 

'choices' => array(
            array("A. 10", "B. 8", "C. 11 <br>"),
            array("A. Ax Kick, Flying Sidekick, Back kick, Front Kick", "B. Front Kick, Side Kick, Back Kick, Roundhouse Kick", "C. Front Kick, Back Kick, Side Kick, Hook Kick <br>"),
            array("A. 1963", "B. 1940s", "C. 1980 <br>"),
            array("A. The way of the foot and fist", "B. To fight with foot and fist", "C. To fight and defend <br>"),
            array("A. South Korea", "B. China", "C. Japan <br>"),
            ),

 'correct' => array("C. 11", 
                "B. Front Kick, Side Kick, Back Kick, Roundhouse Kick", 
                "A. 1963", 
                "A. The way of the foot and fist", 
                "A. South Korea"),
);//end of $quiz array


//Questions
foreach($quiz['questions'] as $i => $question){
    echo $question;

    foreach($quiz['choices'][$i] as $j => $choice){
        echo "<input type='radio' name='$i'>{$choice}<br>";
    }
    //Validation
    if(isset($_POST['submit'])){
        if($_POST[$i] == $quiz['correct'][$i]){
            echo 'Please select an answer.';
        }
    }
}


我想您需要:
“$choice”
并打印($\u POST['selected'])
当我这样做时,它会告诉我:未定义的变量:id。将括号放在name=''中不会导致只创建一个元素的额外数组吗?