How can I serializeArray with a structure based on key value? : <p>I am creating an Array from a form via <code>serializeArray()</code> in jQuery:</p>

<pre><code>var form = $(this).closest('form');
var formData = form.serializeArray();
</code></pre>

<p>If I output this with <code>alert(formData.toSource());</code> I get the result:</p>

<pre><code>[{name:"form[username]", value:"1"}, {name:"form[email]", value:"1@12.sw"}, {name:"form[is_active]", value:"1"}, {name:"form[plainPassword][first]", value:""}, {name:"form[plainPassword][second]", value:""}, {name:"form[id]", value:"9"}, {name:"form[_token]", value:"Mk"}]
</code></pre>

<p>If I capture the data via Ajax to php with <code>$data = $request-&gt;request-&gt;get('data');</code>I get the following Array as a result:</p>

<pre><code>array(7) {
  [0]=&gt;
  array(2) {
    ["name"]=&gt;
    string(14) "form[username]"
    ["value"]=&gt;
    string(1) "1"
  }
  [1]=&gt;
  array(2) {
    ["name"]=&gt;
    string(11) "form[email]"
    ["value"]=&gt;
    string(7) "1@12.sw"
  }
  [2]=&gt;
  array(2) {
    ["name"]=&gt;
    string(15) "form[is_active]"
    ["value"]=&gt;
    string(1) "1"
  }
  [3]=&gt;
  array(2) {
    ["name"]=&gt;
    string(26) "form[plainPassword][first]"
    ["value"]=&gt;
    string(0) ""
  }
  [4]=&gt;
  array(2) {
    ["name"]=&gt;
    string(27) "form[plainPassword][second]"
    ["value"]=&gt;
    string(0) ""
  }
  [5]=&gt;
  array(2) {
    ["name"]=&gt;
    string(8) "form[id]"
    ["value"]=&gt;
    string(1) "9"
  }
  [6]=&gt;
  array(2) {
    ["name"]=&gt;
    string(12) "form[_token]"
    ["value"]=&gt;
    string(43) "Mk"
  }
}
</code></pre>

<p>The array that I would actually need is something like this:</p>

<pre><code>  array(2) {
    ["form[username]"]=&gt;
    string(14) "1"
    ["form[email]"]=&gt;
    string(1) "1@12.sw"
    ["form[is_active]"]=&gt;
    string(1) "1"
    ["form[plainPassword][first]"]=&gt;
    string(0) ""
    ["form[plainPassword][second]"]=&gt;
    string(0) ""
    ["form[id]"]=&gt;
    string(1) "9"
    ["form[id]"]=&gt;
    string(2) "Mk"
  }
</code></pre>

<p>So is it possible to actually serialize the Array differently? What is the best way to achieve the array I would need?</p>
