title: Radio Buttons, multidimensional arrays and PHP
body: <p>I have created a form that allows someone to create a quiz, all of the questions and the answers are stored in a database. You can see a simplified version of the form here: </p>
  
  <p><a href="http://jsfiddle.net/superuntitled/uaTtx/4/" rel="nofollow">http://jsfiddle.net/superuntitled/uaTtx/4/</a></p>
  
  <p>Each question can have an infinite number of answers and only one answer can be correct. To denote the 'correct' answer, I am using radio buttons. </p>
  
  <p>The problem that I am having is that only the selected radio button passes a value to my php code, see a sample <code>$_POST</code> array of values (in this example, three answers for the question "What is a space station?"):</p>
  
  <pre><code>[text] =&gt; Array
      (
          [0] =&gt; A cosmic hotel
          [1] =&gt; An interstellar depot
          [2] =&gt; A closet organizer
      )
  
  [correct] =&gt; Array
      (
          [0] =&gt; 1
      )
  </code></pre>
  
  <p>Even if the correct answer was "An interstellar depot", the first answer "A cosmic hotel" will be entered as the correct answer when I loop through this <code>$_POST</code> array. This is because only a selected radio button will pass a value. </p>
  
  <p>My radio input looks like this:</p>
  
  <pre><code>&lt;input  type="radio" name="answer[1][correct][]" value="1" /&gt;
  </code></pre>
  
  <p>The first set of brackets denotes the question it is associated with, and this number is incremented with each new question.</p>
  
  <p>Does anyone have any ideas on how set the correct answer properly?</p>