title: Multidimensional Array in PHP (form data with checkboxes)
body: <p>I'm new to PHP and having a problem reading checkboxes submitted by a form. Before explaining it i would like to mention that i'm trying to edit a much larger application and the data cannot be sent in any other way. It's just a matter of finding a good method of reading what is being sent.</p>
  
  <p>When a normal text input is sent, the form will post the following:</p>
  
  <pre><code>custom[0][type]="text"
  custom[0][name]="VariableName"
  custom[0][value]="VariableName"
  </code></pre>
  
  <p>Basically there is a main "custom" multidimensional array that has several elements (0,1,2,3 etc) and each element has name and value.</p>
  
  <p>However, when one of the elements is a checkbox, the following stuff gets posted:</p>
  
  <pre><code>custom[1][type]="list"
  custom[1][name]="SelectedOptions"
  custom[1][value]="Value1"
  custom[1][value]="Value3"
  custom[1][value]="Value5"
  </code></pre>
  
  <p>Getting to the PHP side of things, this is the code i'm using to read the data sent by the form. The code below works ok in scenario 1 (with text based inputs) but only reads one value when we have list type custom data.</p>
  
  <pre><code>foreach($_POST['custom'] as $item){
      if($item['value'] != "") echo $item['name'].'='.$item['value']
  }
  </code></pre>
  
  <p>The problem is that <b>$item['value']</b> only reads one of the values, not all 3. How can i get all 3 values in a variable ? It probably is a very easy thing...</p>
  
  <p>To put it all combined, this is what it is sent with POST (3 checkboxes are checked for Variable2)</p>
  
  <pre><code>custom[0][name] Variable1
  custom[0][type] text
  custom[0][value]    ValueForVariable1
  custom[1][name] Variable2
  custom[1][type] checkbox
  custom[1][value]    Value1
  custom[1][value]    Value3
  custom[1][value]    Value5
  </code></pre>
  
  <p>And this is what <strong>print_r($_POST)</strong> shows for the posted data above</p>
  
  <pre><code>[custom] =&gt; Array
  (
  [0] =&gt; Array
      (
      [value] =&gt; ValueForVariable1
      [name] =&gt; Variable1
      [type] =&gt; text
      )
  [1] =&gt; Array
      (
      [value] =&gt; Value1
      [name] =&gt; Variable2
      [type] =&gt; checkbox
      )
  </code></pre>
  
  <p>Just to be sure we're all on the same page, the actual data is generated by a more complex system and we can't really change that. I'm interested in seeing how we can read all 3 values for Variable2 that are sent in the POST.</p>
  
  <p>Thanks !</p>