title: Group array values based on key in php?
body: <p>I have a array like this:</p>
  
  <pre><code>$str=
     Array
  (
      [No] =&gt; 101
      [Paper_id] =&gt; WE3P-1
      [Title] =&gt; "a1"
      [Author] =&gt; ABC
      [Aff_list] =&gt; "University of South Florida, Tampa, United States"
      [Abstracts] =&gt; "SLA"
  
  )
  
  Array
  (
      [No] =&gt; 101
      [Paper_id] =&gt; WE3P-1
      [Title] =&gt; "a2"
      [Author] =&gt; DEF
      [Aff_list] =&gt; "University of South Florida, Tampa, United States"
      [Abstracts] =&gt; "SLA "
  
  )
  
  Array
  (
      [No] =&gt; 104
      [Paper_id] =&gt; TU5A-3
      [Title] =&gt; "a3"
      [Author] =&gt; GHI
      [Aff_list] =&gt; "University of Alcala, Alcala de Henares, Spain"
      [Abstracts] =&gt; "Microwave"
  
  )
  </code></pre>
  
  <p>I want to group elements in the array based upon 'No' as primary key. The output should look like this:</p>
  
  <pre><code> array(6) {
    ["No"]=&gt;
    string(6) "101"
    ["Paper_id"]=&gt;
    string(6) "WE3P-1"
    ["Title"]=&gt;
    string(80) ""a-1"
    ["Author"]=&gt;
    string(14) "ABC"
    ["Aff_list"]=&gt;
    string(51) ""University of South Florida, Tampa, United States""
    ["Abstracts"]=&gt;
    string(5) ""(SLA)"
  "
  }
  array(6) {
    ["No"]=&gt;
    string(3) "104"
    ["Paper_id"]=&gt;
    string(6) "TU5A-3"
    ["Title"]=&gt;
    string(40) "a2"
    ["Author"]=&gt;
    string(20) "DEF"
    ["Aff_list"]=&gt;
    string(48) ""University of Alcala, Alcala de Henares, Spain""
    ["Abstracts"]=&gt;
    string(9) ""Microwave"
  "
  }
  </code></pre>
  
  <p>Note that the Author's value got merged with respect to the primary key 'No'.Can anyone help me out from this, please?</p>
  
  <p>I tried doing this:</p>
  
  <pre><code>foreach($paper_info as $element) {
      foreach($element as $v) {
          $id = $element['No'];
          if (!isset($out[$id])) {
              $out[$id] = [
                  'No' =&gt; $element['No'],
                  'Paper_id' =&gt; $element['Paper_id'],
                  'Title' =&gt; $element['Title'],
                  'Authors' =&gt; [],
                  'Aff_list' =&gt; $element['Aff_list'],
                  'Abstracts' =&gt; $element['Abstracts']
              ];
          }
          $out[$id]['Authors'][] = ['Authors' =&gt; $element['Author']];
      }
  }
  </code></pre>