How can I add a sub-array structure in my results? $_POST I'm building a form. In that form I have a lot of checkboxes. Normally, It's possible to make an array of some checkboxes (with name attribute).

&lt;input type="text" name="reservatie[0][1]" /&gt;
&lt;input type="text" name="reservatie[0][2]" /&gt;
&lt;input type="text" name="reservatie[1][1]" /&gt;


Normally I would have this result with print_r($_POST);

Array(
    [reservatie] =&gt; Array(
        [0] =&gt; Array (
            [1] =&gt; value
            [2] =&gt; value
            )
        )
        [1] =&gt; Array
        (
            [1] =&gt; value
        )
    )
)


I tried to add the name attribute, but the $_POST takes the structure of $form. But how can I add a sub-array structure in my results?

foreach($result as $time) {
                    $form['reservatie'][$item-&gt;id][$time-&gt;id] = array(
                          '#type' =&gt; 'checkbox',
                          '#return_value' =&gt; 1,
                          '#default_value' =&gt; 0,
                          '#prefix' =&gt; '&lt;td&gt;',
                          '#suffix' =&gt; '&lt;/td&gt;',
                          '#attributes' =&gt; array('name' =&gt; 'reservatie[0]['.$time-&gt;id.']')          
                    );
                }


This is what I get:

array(42) {
  ["date"]=&gt;
  string(10) "01/07/2016"
  ["reservatie[1][1]"]=&gt;
  int(0)
  ["reservatie[1][2]"]=&gt;
  int(0)
  ["reservatie[1][3]"]=&gt;
  int(0)
  ["reservatie[1][4]"]=&gt;
  int(0)
  ["reservatie[1][5]"]=&gt;
  int(0)
  ["reservatie[1][6]"]=&gt;
  int(0)
  ["reservatie[1][7]"]=&gt;
  int(0)
  ["reservatie[1][8]"]=&gt;
  int(0)
  ["reservatie[1][9]"]=&gt;
  int(0)
  ["reservatie[2][1]"]=&gt;
  int(0)
...
)
I managed to solve my own problem. It was a problem with the #tree.
I have to set #tree in the parents to true..

So if you want an array with the following structure:

array {
    ["parent"]=&gt;
     array(4) {
        [1]=&gt;
        array(9) {
          [1]=&gt;
          int(1)
          [2]=&gt;
          int(0)
          [3]=&gt;
          int(0)
          [4]=&gt;
          int(0)
          [5]=&gt;
          int(0)
          [6]=&gt;
          int(0)
          [7]=&gt;
          int(0)
          [8]=&gt;
          int(0)
          [9]=&gt;
          int(0)
        }
    }
}


I had to configure #tree for the parents (2 here), and not only for the children

['parent']['#tree'] = true
['parent'][1]['#tree'] = true


I figured it out after trying and reading https://www.drupal.org/node/48643 (Archived, but it worked for me ;) )