title: create array multidimensional php in more loop [edit]
body: <p>i have this code php:</p>
  
  <pre><code>foreach($first as $row2){  // cycling once
  
         foreach($second as $row){   //    cycles x times
  
                  ....
                  echo $Hval1;//course changes value every cycle
                  echo $Hval2;//course changes value every cycle
  
                  $HeaderArray[]=array('Hval1'=&gt;$Hval1,'Hval2'=&gt;$Hval2); 
  
                      for($i=0;$i&lt;$conta;++$i){   //    cycles x times
  
                         ....
                         echo $Bval1;//course changes value every cycle
                         echo $Bval2;//course changes value every cycle
                         echo $bval3;//course changes value every cycle
  
                      $BArray[]= array('Bval1'=&gt;$Bval1,'Bval2'=&gt;$Bval2,'Bval3'=&gt;$Bval3);
                      $groupsArray[]=array($BArray);
                      }//end for cycles
                      $blockArray[]=array('header'=&gt;$headerArray,'mach'=&gt;$groupsArray);
  
         } //end second cycles
         $totalArray[]=('incontri'=&gt;$blockArray);
  
  
  } //end first cycle
  
  echo print_r($totalArray);
  </code></pre>
  
  <p>for each $second cycle there are one o more groups $groupsArray Bval 'mach' (cycle for) going in the same array. All these (cycle $second) go into a Array 'incontri'.</p>
  
  <p>I would like to get an array like this:</p>
  
  <pre><code> ['incontri'
            [
             [
             'header'['Hval1'=&gt;$Hval1,'Hval2'=&gt;$Hval2],
             'mach'[
                    ['Bval1'=&gt;$Bval1,'Bval2'=&gt;$Bval2,'Bval3'=&gt;$Bval3],
                    ['Bval1'=&gt;$Bval1,'Bval2'=&gt;$Bval2,'Bval3'=&gt;$Bval3]
                    ]
             ],
             [
             'header'['Hval1'=&gt;$Hval1,'Hval2'=&gt;$Hval2],
             'mach'[
                   ['Bval1'=&gt;$Bval1,'Bval2'=&gt;$Bval2,'Bval3'=&gt;$Bval3],
                   ['Bval1'=&gt;$Bval1,'Bval2'=&gt;$Bval2,'Bval3'=&gt;$Bval3]
                   ]
             ],
             ...
            ]
  ]
  </code></pre>
  
  <p>my code php not work fine;</p>