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:
[0] => Array ( [calldate] => 2014-12-01 08:31:47 [src] => 1234 [duration] => 190 )
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.
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 index 11
9123
calls and is answered within 12 seconds but they call back around 30 minutes later and their second call at 9:55:31
is answered within 15 seconds, this would need to be to separate items in the final array.
The src's are just fictional and will not be the numbers in the real world.
Array (
[0] => Array ( [calldate] => 2014-12-01 08:31:47 [src] => 1234 [duration] => 30 )
[1] => Array ( [calldate] => 2014-12-01 08:32:22 [src] => 1234 [duration] => 30 )
[2] => Array ( [calldate] => 2014-12-01 08:32:57 [src] => 1234 [duration] => 30 )
[3] => Array ( [calldate] => 2014-12-01 08:33:32 [src] => 1234 [duration] => 30 )
[4] => Array ( [calldate] => 2014-12-01 08:34:07 [src] => 1234 [duration] => 30 )
[5] => Array ( [calldate] => 2014-12-01 08:34:42 [src] => 1234 [duration] => 30 )
[6] => Array ( [calldate] => 2014-12-01 08:35:12 [src] => 1234 [duration] => 10 )
[7] => Array ( [calldate] => 2014-12-01 08:35:47 [src] => 1234 [duration] => 30 )
[8] => Array ( [calldate] => 2014-12-01 08:36:22 [src] => 1234 [duration] => 30 )
[9] => Array ( [calldate] => 2014-12-01 08:51:20 [src] => 5678 [duration] => 15 )
[10] => Array ( [calldate] => 2014-12-01 09:09:14 [src] => 5678 [duration] => 10 )
[11] => Array ( [calldate] => 2014-12-01 09:22:58 [src] => 9123 [duration] => 12 )
[12] => Array ( [calldate] => 2014-12-01 09:42:42 [src] => 4567 [duration] => 30 )
[13] => Array ( [calldate] => 2014-12-01 09:43:17 [src] => 4567 [duration] => 30 )
[14] => Array ( [calldate] => 2014-12-01 09:43:52 [src] => 4567 [duration] => 30 )
[15] => Array ( [calldate] => 2014-12-01 09:44:27 [src] => 4567 [duration] => 30 )
[16] => Array ( [calldate] => 2014-12-01 09:45:02 [src] => 4567 [duration] => 29 )
[17] => Array ( [calldate] => 2014-12-01 09:55:31 [src] => 9123 [duration] => 15 )
[18] => Array ( [calldate] => 2014-12-01 10:34:29 [src] => 8912 [duration] => 10 )
[19] => Array ( [calldate] => 2014-12-01 13:26:29 [src] => 3456 [duration] => 30 )
[20] => Array ( [calldate] => 2014-12-01 13:27:04 [src] => 3456 [duration] => 30 )
[21] => Array ( [calldate] => 2014-12-01 13:27:39 [src] => 3456 [duration] => 30 )
[22] => Array ( [calldate] => 2014-12-01 13:28:14 [src] => 3456 [duration] => 30 )
[23] => Array ( [calldate] => 2014-12-01 13:28:49 [src] => 3456 [duration] => 30 )
[24] => Array ( [calldate] => 2014-12-01 13:29:24 [src] => 3456 [duration] => 30 )
[25] => Array ( [calldate] => 2014-12-01 13:29:54 [src] => 3456 [duration] => 4 )
)
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:
$adjusted = array();
for($i = 1; $i < sizeof($adjustedTotalCallsExt); $i++) {
$previousCall = $adjustedTotalCallsExt[$i-1];
$currentCall = $adjustedTotalCallsExt[$i];
if($previousCall['src'] == $currentCall['src']) {
$adjusted[] = $previousCall['duration'] + $currentCall['duration'];
}
else {
$adjusted[] = $currentCall['duration'];
}
}