title: Combine two array using a field in PHP
body: <p>I have an array in which i want to combine the common fields together.
  So that the common names get grouped together and they contain the common values of that particular name.
  Below is my array </p>
  
  <pre><code>[
    [
      count_employee: 2,
      name: "Harry"
    ],
    [
      count_employee: 61,
      name: "Jack"
    ],
    [
      count_employee: 11,
      name: "John"
    ],
    [
      count_warehouse: 1,
      name: "Harry"
    ],
    [
      count_warehouse: 77,
      name: "John"
    ],
    [
      count_warehouse: 45,
      name: "Jack"
    ]
  ]
  </code></pre>
  
  
  
  <p>I want the output to be </p>
  
  <pre><code>[
    [
      name: "Harry",
      count_employee:2
      count_warehouse:1
    ],
    [
      name: "Jack",
      count_employee: 61
      count_warehouse: 45
    ],
    [
      name: "John",
      count_employee:11
      count_warehouse:77
    ],
  ]
  </code></pre>
  
  
  
  <p>So far i have tried this out </p>
  
  <pre><code>foreach ($data as $key =&gt; $value) {
        $group[$value['name']]['name'] = $value['name'];
        $group[$value['name']][$key]['count_employee'] = $value['count_employee'];
        $group[$value['name']][$key]['count_warehouse'] = $value['count_warehouse'];
  }
  </code></pre>