title: Multidemensional array filter out duplicates within group
body: <p>Im trying to remove the duplicate array value group based on the same dates(only keep 1 group).</p>
  
  <p>Also take the number in the "1" key (above the pid key) and add it together with the duplicated grouped.</p>
  
  <p>The issue im having is the each group under hour is "only" supposes to filter with duplicate groups under the same "hour" section.</p>
  
  <p>Here's the array im starting with:</p>
  
  <pre><code>Array(
      [1488] =&gt; Array
          (
              [hours] =&gt; Array
                  (
                      [0] =&gt; Array
                          (
                              [0] =&gt; 2016/07/11 - 2016/07/17
                              [1] =&gt; 37
                              [pid] =&gt; 1488
                          )
  
                      [1] =&gt; Array
                          (
                              [0] =&gt; 2016/07/04 - 2016/07/10
                              [1] =&gt; 51
                              [pid] =&gt; 1488
                          )
  
                      [2] =&gt; Array
                          (
                              [0] =&gt; 2016/07/04 - 2016/07/10
                              [1] =&gt; 44
                              [pid] =&gt; 1488
                          )
  
                      [3] =&gt; Array
                          (
                              [0] =&gt; 2016/07/04 - 2016/07/10
                              [1] =&gt; 22
                              [pid] =&gt; 1488
                          )
  
                  )
  
          )
  
      [2] =&gt; Array
          (
              [hours] =&gt; Array
                  (
                      [0] =&gt; Array
                          (
                              [0] =&gt; 2016/07/04 - 2016/07/10
                              [1] =&gt; 9.5
                              [pid] =&gt; 2
                          )
  
                      [1] =&gt; Array
                          (
                              [0] =&gt; 2016/07/04 - 2016/07/10
                              [1] =&gt; 8
                              [pid] =&gt; 2
                          )
  
                      [2] =&gt; Array
                          (
                              [0] =&gt; 2016/07/04 - 2016/07/10
                              [1] =&gt; 7
                              [pid] =&gt; 2
                          )
  
                      [3] =&gt; Array
                          (
                              [0] =&gt; 2016/07/11 - 2016/07/17
                              [1] =&gt; 5
                              [pid] =&gt; 2
                          )
  
                  )
  
          )
  
  )
  </code></pre>
  
  <p>Here what i need it to look like:</p>
  
  <pre><code>Array(
      [0] =&gt; Array
          (
              [hours] =&gt; Array
                  (
                      [0] =&gt; Array
                          (
                              [0] =&gt; 2016/07/11 - 2016/07/17
                              [1] =&gt; 37
                              [pid] =&gt; 1488
                          )
  
                      [1] =&gt; Array
                          (
                              [0] =&gt; 2016/07/04 - 2016/07/10
                              [1] =&gt; 117
                              [pid] =&gt; 1488
                          )
  
                  )
  
          )
  
      [1] =&gt; Array
          (
              [hours] =&gt; Array
                  (
                      [0] =&gt; Array
                          (
                              [0] =&gt; 2016/07/04 - 2016/07/10
                              [1] =&gt; 24.5
                              [pid] =&gt; 2
                          )
  
                      [1] =&gt; Array
                          (
                              [0] =&gt; 2016/07/11 - 2016/07/17
                              [1] =&gt; 5
                              [pid] =&gt; 2
                          )
  
                  )
  
          )
  
  )
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>$temp_array = array();
      $w = 0;
      $key_array = array();
  
      $new_array = array();
  
      foreach($project_hours as $old_arrs) {
  
  
              foreach ($old_arrs["hours"] as $val) {
                  if (!in_array($val[0], $key_array)) {
                      $key_array[$w] = $val[0];
                      $temp_array[$w] = $val;
  
                  } else {
                      $ser = array_search($val[0], $key_array);
                      $temp_array[$ser][1] += $val[1];
                  }
  
                  $w++;
  
                 $old_arrs["hours"] = $temp_array;
  
              }
  
  
          $new_array[] = $old_arrs;
      }
  
      echo '&lt;pre&gt;';
      print_r($new_array);
      echo '&lt;/pre&gt;';
  </code></pre>