title: How to pass array with all elements with jquery to php
body: <p>I am trying to pass an array from jQuery to PHP.</p>
  
  <pre><code>&lt;input type="checkbox" id="name1" name="name[]" value="name1"&gt; Name1
  &lt;input type="checkbox" id="name2" name="name[]" value="name2"&gt; Name2
  &lt;input type="checkbox" id="name3" name="name[]" value="name3"&gt; Name3&lt;br /&gt;
  
  &lt;input type="checkbox" id="phone1" name="phone[]" value="samsung"&gt; Samsung
  &lt;input type="checkbox" id="phone2" name="phone[]" value="nokia"&gt; Nokia
  &lt;input type="checkbox" id="phone3" name="phone[]" value="motorola"&gt; Motorola&lt;br /&gt;
  </code></pre>
  
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function() {
      $(":checkbox").on('change', function() {
          var group = [];
          var mygroup = {};
  
          $(':checkbox:checked').each(function(i){    
              var val = this.value;
              var name = this.name;   
              mygroup[name] = val;
              var all = name + "=" + val;
              group.push(all);
  
              $.ajax({ 
                  type: "POST", 
                  url: 'testdraft1.php',
                  data: mygroup, // TRIED WITH group and all also. Doesn't work.
                  success: function(data) {
                      $("#result").html(data);
                  }
              });     
          });
      });
  });
  </code></pre>
  
  <p>With this code the array is passed to PHP but with only 1 element. Even if I select multiple elements. What am I doing wrong?</p>