I have array like this
[
(int) 0 => [
'Servloc' => '1',
'WasteText' => 'Container1',
'ContainerText' => 'Container Type 1',
'ContainerCount' => (int) 5,
],
(int) 1 => [
'Servloc' => '1',
'WasteText' => 'Container1',
'ContainerText' => 'Container Type 1',
'ContainerCount' => (int) 4,
],
(int) 2 => [
'Servloc' => '1',
'WasteText' => 'Container1',
'ContainerText' => 'Container Type 1',
'ContainerCount' => (int) 3,
],
(int) 3 => [
'Servloc' => '1',
'WasteText' => 'Container2',
'ContainerText' => 'Container Type 1',
'ContainerCount' => (int) 3,
],
(int) 4 => [
'Servloc' => '2',
'WasteText' => 'Container1',
'ContainerText' => 'Container Type 2',
'ContainerCount' => (int) 1,
],
]
I need to group this array based on same values of Servloc, WasteText, ContainerText PLUS SUM all values from ContainerCount.
So result for this array should be:
[
(int) 0 => [
'Servloc' => '1',
'WasteText' => 'Container1',
'ContainerText' => 'Container Type 1',
'ContainerCount' => (int) 12,
],
(int) 3 => [
'Servloc' => '1',
'WasteText' => 'Container2',
'ContainerText' => 'Container Type 1',
'ContainerCount' => (int) 3,
],
(int) 4 => [
'Servloc' => '2',
'WasteText' => 'Container1',
'ContainerText' => 'Container Type 2',
'ContainerCount' => (int) 1,
],
]
I have tried to foreach first array twice and compare those values, if they are same then put in another array as result. But it doesnt work....