组根据名称将JS数组序列化为类似的数组

I serialized my form with $('#myForm').serializeArray();. I get all the inputs but my form is complex and I need to group the same names.

In my ajaxController :

$data = json_decode($request->getParameter('data'));    
print_r($data);

Here's the result of the output:

array (size=8)
  0 => 
    object(stdClass)[192]
      public 'name' => string 'evaluation_candidature[id_evaluateur_candidature]' (length=49)
      public 'value' => string '2899' (length=4)
  1 => 
    object(stdClass)[196]
      public 'name' => string 'evaluation_candidature[_csrf_token]' (length=35)
      public 'value' => string '51c7f3442410a04e926c7a7abd1082d9' (length=32)
  2 => 
    object(stdClass)[197]
      public 'name' => string 'evaluation_candidature[note_globale]' (length=36)
      public 'value' => string 'A+' (length=2)
  3 => 
    object(stdClass)[198]
      public 'name' => string 'evaluation_candidature[appreciation]' (length=36)
      public 'value' => string 'je teste l'évaluation
TB!' (length=27)
  4 => 
    object(stdClass)[199]
      public 'name' => string 'evaluation_candidature[Apport pour le laboratoire_1][note]' (length=58)
      public 'value' => string '1' (length=1)
  5 => 
    object(stdClass)[200]
      public 'name' => string 'evaluation_candidature[Apport pour le laboratoire_1][id_evaluateur_candidature]' (length=79)
      public 'value' => string '2899' (length=4)
  6 => 
    object(stdClass)[201]
      public 'name' => string 'evaluation_candidature[Apport pour le laboratoire_1][evaluation_critere_id]' (length=75)
      public 'value' => string '91' (length=2)
  7 => 
    object(stdClass)[202]
      public 'name' => string 'evaluation_candidature[Apport pour le laboratoire_1][remarque]' (length=62)
      public 'value' => string '' (length=0)

I need to group all evaluation_candidature[Apport pour le laboratoire_1] and also I need to group evaluation_candidature.

The problem is that I don't know the names beforehand. The names could be different as it depends from the form collection. I hope someone can help me.

Update i tried to group in javascript :

var datas = [],
        serialized = $('#myForm').serializeArray(),
        i;
    for (i=0; i<serialized.length; i+=2) {
        var tmpObj = {};
        tmpObj[ serialized[i].name ] = serialized[i].value;
        tmpObj[ serialized[i+1].name ] = serialized[i+1].value;
        datas.push(tmpObj);
    }

    console.log(datas);

Here the output :

array (size=6)
  0 => 
    object(stdClass)[192]
      public 'evaluation_candidature[id_evaluateur_candidature]' => string '2899' (length=4)
      public 'evaluation_candidature[_csrf_token]' => string '51c7f3442410a04e926c7a7abd1082d9' (length=32)
  1 => 
    object(stdClass)[196]
      public 'evaluation_candidature[note_globale]' => string 'A+' (length=2)
      public 'evaluation_candidature[appreciation]' => string 'je teste l'évaluation
TB!' (length=27)
  2 => 
    object(stdClass)[197]
      public 'evaluation_candidature[Apport pour le laboratoire_1][note]' => string '1' (length=1)
      public 'evaluation_candidature[Apport pour le laboratoire_1][id_evaluateur_candidature]' => string '2899' (length=4)
  3 => 
    object(stdClass)[198]
      public 'evaluation_candidature[Apport pour le laboratoire_1][evaluation_critere_id]' => string '91' (length=2)
      public 'evaluation_candidature[Apport pour le laboratoire_1][remarque]' => string '' (length=0)

As you can see i still have duplication.

I am 100% sure you need PHP's array_filter($your_array, "callBackFunction"). after you collected the form details by JS pass it to PHP and have a call back function to sort it the way you want it using your functions or built in function such as array_sort(), array_unique(), ....

$sorted_array = array_filter(
    $my_array, 
    function($value) {
        // your code to filter through and group them
        foreach() {
            $new_group_array[$key] = $value;
        }
        return $new_grouped_array;
    }
);

or if you want to do it by KEY

// list of unique array keys
$new_unique_array = array_unique($my_array);
$array_groups = array('something', 'something02', ...)
$sorted_array = array_filter(
    $new_unique_array,
    function ($key) use ($allowed) {
       // in_array($key, $allowed);
    },
    ARRAY_FILTER_USE_KEY
);