title: How do I merge data into Multidimentional array based on a value in current/previous array
body: <p>I am building some phone statistics and have the output below which I need to basically merge the same src and add the duration together. For example array index 0 through to 6 would merge into one array that would look like the following:</p>
  
  <pre><code>[0] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:31:47 [src] =&gt; 1234 [duration] =&gt; 190 )
  </code></pre>
  
  <p>You're probably thinking shouldn't it be index 0 through to 8 but because index 6 was only 10 seconds this basically signifies that the call was answered. It can be assumed that if a call duration is 30 seconds then it has not been answered.</p>
  
  <p>It's not as simple as just finding the src that match in the array and adding all the durations together though as you will see in <code>index 11</code> <code>9123</code> calls and is answered within 12 seconds but they call back around 30 minutes later and their second call at <code>9:55:31</code> is answered within 15 seconds, this would need to be to separate items in the final array.</p>
  
  <p>The src's are just fictional and will not be the numbers in the real world.</p>
  
  <pre><code>Array ( 
  
      [0] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:31:47 [src] =&gt; 1234 [duration] =&gt; 30 ) 
      [1] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:32:22 [src] =&gt; 1234 [duration] =&gt; 30 ) 
      [2] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:32:57 [src] =&gt; 1234 [duration] =&gt; 30 ) 
      [3] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:33:32 [src] =&gt; 1234 [duration] =&gt; 30 ) 
      [4] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:34:07 [src] =&gt; 1234 [duration] =&gt; 30 ) 
      [5] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:34:42 [src] =&gt; 1234 [duration] =&gt; 30 ) 
      [6] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:35:12 [src] =&gt; 1234 [duration] =&gt; 10 ) 
      [7] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:35:47 [src] =&gt; 1234 [duration] =&gt; 30 ) 
      [8] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:36:22 [src] =&gt; 1234 [duration] =&gt; 30 ) 
      [9] =&gt; Array ( [calldate] =&gt; 2014-12-01 08:51:20 [src] =&gt; 5678 [duration] =&gt; 15 ) 
      [10] =&gt; Array ( [calldate] =&gt; 2014-12-01 09:09:14 [src] =&gt; 5678 [duration] =&gt; 10 ) 
      [11] =&gt; Array ( [calldate] =&gt; 2014-12-01 09:22:58 [src] =&gt; 9123 [duration] =&gt; 12 ) 
      [12] =&gt; Array ( [calldate] =&gt; 2014-12-01 09:42:42 [src] =&gt; 4567 [duration] =&gt; 30 ) 
      [13] =&gt; Array ( [calldate] =&gt; 2014-12-01 09:43:17 [src] =&gt; 4567 [duration] =&gt; 30 ) 
      [14] =&gt; Array ( [calldate] =&gt; 2014-12-01 09:43:52 [src] =&gt; 4567 [duration] =&gt; 30 ) 
      [15] =&gt; Array ( [calldate] =&gt; 2014-12-01 09:44:27 [src] =&gt; 4567 [duration] =&gt; 30 ) 
      [16] =&gt; Array ( [calldate] =&gt; 2014-12-01 09:45:02 [src] =&gt; 4567 [duration] =&gt; 29 ) 
      [17] =&gt; Array ( [calldate] =&gt; 2014-12-01 09:55:31 [src] =&gt; 9123 [duration] =&gt; 15 ) 
      [18] =&gt; Array ( [calldate] =&gt; 2014-12-01 10:34:29 [src] =&gt; 8912 [duration] =&gt; 10 ) 
      [19] =&gt; Array ( [calldate] =&gt; 2014-12-01 13:26:29 [src] =&gt; 3456 [duration] =&gt; 30 ) 
      [20] =&gt; Array ( [calldate] =&gt; 2014-12-01 13:27:04 [src] =&gt; 3456 [duration] =&gt; 30 ) 
      [21] =&gt; Array ( [calldate] =&gt; 2014-12-01 13:27:39 [src] =&gt; 3456 [duration] =&gt; 30 ) 
      [22] =&gt; Array ( [calldate] =&gt; 2014-12-01 13:28:14 [src] =&gt; 3456 [duration] =&gt; 30 ) 
      [23] =&gt; Array ( [calldate] =&gt; 2014-12-01 13:28:49 [src] =&gt; 3456 [duration] =&gt; 30 ) 
      [24] =&gt; Array ( [calldate] =&gt; 2014-12-01 13:29:24 [src] =&gt; 3456 [duration] =&gt; 30 ) 
      [25] =&gt; Array ( [calldate] =&gt; 2014-12-01 13:29:54 [src] =&gt; 3456 [duration] =&gt; 4 ) 
  )
  </code></pre>
  
  <p>I believe this would need to be some sort of for loop that would have to compare current/previous calls and add them into a new array. I have done this but it isn't giving the expected result as it only adds together the previous and current call if the src matches. Here is the code I currently have:</p>
  
  <pre><code>$adjusted = array();
  for($i = 1; $i &lt; sizeof($adjustedTotalCallsExt); $i++) {
  $previousCall = $adjustedTotalCallsExt[$i-1];
  $currentCall = $adjustedTotalCallsExt[$i];
      if($previousCall['src'] == $currentCall['src']) {
          $adjusted[] = $previousCall['duration'] + $currentCall['duration'];
      }
      else {
      $adjusted[] = $currentCall['duration'];
      }
  }     
  </code></pre>