I have a form with a list of radio buttons:

<input type="radio" name="answer_arr[]">
<input type="radio" name="answer_arr[]">
<input type="radio" name="answer_arr[]">

And I would like to determine which radio button was selected in my PHP code. I've tried to create a loop, but it just loops through once, although there are 3 items in the array. Can some one tell me if this possible or if there's another way around this. Your help would be much appreciated.

Thank you

    If you give multiple radio buttons the same name only one of them can be selected, and therefore only one will be sent to your script. You normally give a group of radio buttons the same name (minus the array postfix) and different values, then check the button name in your script to see which value it contains.

      Is this what you mean?

      <input type="radio" name="answer_arr" value="1">
      <input type="radio" name="answer_arr" value="2">
      <input type="radio" name="answer_arr" value="3">

      Then how do I go abouts getting the value in my php code?

      I'm not sure what you mean by button name.

        Same way you go about getting the values of every other field in your form. By button name I meant the name of the radio button group.

        if ($_POST['answer_arr'] == '1') {
            echo 'Button 1 selected';
        }
          Write a Reply...