title: post ajax data with multiple arrays to php
body: <p>I've successfully posted a single serialized array, but I can't figure out how to post more than one array in an AJAX post. Here is my code:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;td&gt;&lt;input type="text" name='item_name[]' id="item_name" class="form-control" autocomplete="off"&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="number" name='quantity[]' id="quantity" class="form-control" autocomplete="off"&gt;&lt;/td&gt;
  </code></pre>
  
  <p><strong>jquery</strong></p>
  
  <pre><code>$("#create_order").click(function(){  
  
      var item_name = $('[name="item_name[]"]').serialize();
      var quantity = $('[name="quantity[]"]').serialize();
  
      $.ajax({
  
          url: "includes/ajax_new_order.php",
          data: {item_name:item_name, quantity:quantity},
  
          type: "POST",
  
          success:function(data){ 
  
              $("#editModal").modal('hide'); 
  
              $('#create_order').html('&lt;span class="glyphicon glyphicon-ok" aria-hidden="true"&gt;&lt;/span&gt; Save');
          }
      });
  });
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php require("../init.php");
  
      $item_name = $_POST['item_name'];
      $quantity = $_POST['quantity'];
  
      foreach (array_combine($item_name, $quantity) as $key1 =&gt; $key2) {
  
        $query = $database-&gt;query("INSERT INTO order_tb(item,quantity) VALUES('$key1','$key2') ");
        if ($query) {
          echo "&lt;p&gt;Success&lt;/p&gt;";
        }
        else { 
          echo "&lt;p&gt;Failed&lt;/p&gt;"; 
        } 
      }
  ?&gt;
  </code></pre>
  
  <p>One array works fine, however when I try to add a second array <strong><em>quantity</em></strong> to the <strong><em>data:</em></strong> field, it doesn't work.</p>