title: html multidimensional array to php multidimensional array - array overwritten
body: <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="pkg1-items"&gt;
    &lt;div class="col-md-2 "&gt;
      &lt;label&gt;Item 1 :&lt;/label&gt;
  
    &lt;/div&gt;
    &lt;div class="col-md-2 "&gt;
      &lt;div class="input-control select " data-role="input"&gt;
        &lt;input name="item[0][name]" type="text " placeholder="Enter Item " required&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="col-md-2 "&gt;
      &lt;label&gt;Option 1 :&lt;/label&gt;
  
    &lt;/div&gt;
    &lt;div class="col-md-2 "&gt;
      &lt;div class="input-control select " data-role="input"&gt;
        &lt;input name="item[0][option1]" type="text " placeholder="Enter Option To Item" required&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="col-md-2 "&gt;
      &lt;label&gt;Option 2 :&lt;/label&gt;
  
    &lt;/div&gt;
    &lt;div class="col-md-2 "&gt;
      &lt;div class="input-control select " data-role="input"&gt;
        &lt;input name="item[0][option2]" type="text " placeholder="Enter Option To Item  " required&gt;
  
      &lt;/div&gt;
    &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>script which dynamically adds input </p>
  
  <pre><code>$(document).on('click', 'label[id^="pkg"]', function() {
              var pkg = this.id;
              var clickeditem  = '#'+this.id +'-items';
              i++;
              $('&lt;div class="clearfix"&gt;&lt;/div&gt;&lt;div class="col-md-2 "&gt; &lt;label&gt;Item  : &lt;/label&gt;&lt;/div&gt;&lt;div class="col-md-2 "&gt; &lt;div class="input-control select " data-role="input"&gt; &lt;input name="item['+i+']['+'name'+']" type="text " placeholder="Enter Item " required&gt; &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-2 "&gt; &lt;label&gt;Option 1 : &lt;/label&gt;&lt;/div&gt;&lt;div class="col-md-2 "&gt; &lt;div class="input-control select " data-role="input"&gt; &lt;input name="item['+i+']['+'option1'+']" type="text " placeholder="Enter Option To Item" required&gt; &lt;/div&gt;&lt;/div&gt;&lt;div class="col-md-2 "&gt; &lt;label&gt;Option 2 : &lt;/label&gt;&lt;/div&gt;&lt;div class="col-md-2 "&gt; &lt;div class="input-control select " data-role="input"&gt; &lt;input name="item['+i+']['+'option2'+']" type="text " placeholder="Enter Option To Item " required&gt; &lt;/div&gt;&lt;/div&gt;').appendTo(clickeditem); 
  
  
              return false;
      });
  </code></pre>
  
  <p>send.php </p>
  
  <pre><code>$i=0;
          //$string = "";
          $items = array( array() ); 
          $item = $_POST['item'];
          $icnt = count($items); 
          $pkg = $_POST['Packages'];
          $nop = count($_POST['Packages']);
  
          for ( $i = 0 ; $i&lt; $icnt ; $i ++ ) {
              $items[$i][0] = $item[$i]['name'];
              $items[$i][1] = $item[$i]['option1'];
              $items[$i][2] = $item[$i]['option2'];
  
  
  
          } 
      echo '&lt;br/&gt;&lt;hr/&gt;';
              print_r($items);
              echo '&lt;br/&gt;&lt;hr/&gt;';
      }
  </code></pre>
  
  <p>The above gives output - 
  Array ( [0] => Array ( [0] => item1[1] => option1[2] => option2) ) </p>
  
  <p>given that the inputs were - item1 , option1 , option2 . Although three or more inputs were added but the array gets overwritten and outputs the last value only . how can I use a dynamic multidimensional array in php . If I define the array with specific row and cols the above will work fine .</p>