I have the following array
Array (
[0] => Array (
[0] => Array (
[productCode] => HQ768H
[startTimeLocal] => 2018-04-17 14:00:00
[endTimeLocal] => 2018-04-17 16:00:00
[totalQuantity] => 2
[amount] => 170
[extras] => Array ()
[transferReturn] =>
[subtotal] => 170
)
[1] => Array (
[productCode] => PLJ6HP
[startTimeLocal] => 2018-04-15 14:00:00
[endTimeLocal] => 2018-04-15 16:00:00
[totalQuantity] => 2
[amount] => 170
[extras] => Array ()
[transferReturn] =>
[subtotal] => 170
)
[2] => Array (
[productCode] => PLJ6HP
[startTimeLocal] => 2018-04-15 14:00:00
[endTimeLocal] => 2018-04-15 16:00:00
[totalQuantity] => 2
[amount] => 170
[extras] => Array ()
[transferReturn] =>
[subtotal] => 170
)
)
)
I am trying to create another array from this using PHP made up of the productCode, startTimeLocal and totalQuantity... but where two or more elements have the same productCode and the same startTimeLocal I need to update the totalQuantity by adding the new value rather then adding a new array element.
The only code I have been able to come up with is a long set of nested foreach loops which don't come anywhere close to performing the actions I need. I am reasonably new to this. If anybody could help out or point me in the right direction I would be very appreciative. Thanks.
Below is what I am trying to achieve...
Array (
[0] => Array (
[0] => Array (
[productCode] => HQ768H
[startTimeLocal] => 2018-04-17 14:00:00
[totalQuantity] => 2
)
[1] => Array (
[productCode] => PLJ6HP
[startTimeLocal] => 2018-04-15 14:00:00
[totalQuantity] => 4
)
)
)