I have an array of around 250 employees. I have duplicates of most employees where one or two elements of their array is different. How do I detect and combine the arrays that have the same "empNum". The one below is an example, when combined I would have 133 elements.
Array
(
[0] => Array
(
[empNum] => 17
[wksWrkd] => 2
[trcode] => 1
[appn] => 51000550000
[totalHours] => 20.00
[rate] => 12.00
[net] => 240.00
[overHours] => .00
[holidayHours] => .00
[overtimePay] => .00
[otherPay] => .00
[holidayPay] => .00
[ctu] => .00
[cta] => .00
[ptu] => .00
[pta] => .00
[sickHours] => .0000
[vacaHours] => .0000
[gross] => 240.00
)
[1] => Array
(
[empNum] => 17
[wksWrkd] => 2
[trcode] => 1
[appn] => 20000560000
[totalHours] => 34.00
[rate] => 12.00
[net] => 408.00
[overHours] => .00
[holidayHours] => .00
[overtimePay] => .00
[otherPay] => .00
[holidayPay] => .00
[ctu] => .00
[cta] => .00
[ptu] => .00
[pta] => .00
[sickHours] => .0000
[vacaHours] => .0000
[gross] => 408.00
)
[2] => Array
(
[empNum] => 17
[wksWrkd] => 2
[trcode] => 1
[appn] => 51000550005
[totalHours] => 54.00
[rate] => 12.00
[net] => 648.00
[overHours] => .00
[holidayHours] => .00
[overtimePay] => .00
[otherPay] => .00
[holidayPay] => .00
[ctu] => .00
[cta] => .00
[ptu] => .00
[pta] => .00
[sickHours] => .0000
[vacaHours] => .0000
[gross] => 648.00
)
[3] => Array
(
[empNum] => 17
[wksWrkd] => 2
[trcode] => 1
[appn] => 20000560005
[totalHours] => 13.00
[rate] => 12.00
[net] => 156.00
[overHours] => .00
[holidayHours] => .00
[overtimePay] => .00
[otherPay] => .00
[holidayPay] => .00
[ctu] => .00
[cta] => .00
[ptu] => .00
[pta] => .00
[sickHours] => .0000
[vacaHours] => .0000
[gross] => 156.00
)
[4] => Array
(
[empNum] => 17
[wksWrkd] => 2
[trcode] => 4
[appn] => 51000550000
[totalHours] => .00
[rate] => .00
[net] => .00
[overHours] => 4.00
[holidayHours] => 72.00
[overtimePay] => .00
[otherPay] => .00
[holidayPay] => .00
[ctu] => .00
[cta] => .00
[ptu] => .00
[pta] => .00
[sickHours] => .0000
[vacaHours] => .0000
[gross] => 72.00
)
[5] => Array
(
[empNum] => 17
[wksWrkd] => 2
[trcode] => 4
[appn] => 51000550005
[totalHours] => .00
[rate] => .00
[net] => .00
[overHours] => .25
[holidayHours] => 4.50
[overtimePay] => .00
[otherPay] => .00
[holidayPay] => .00
[ctu] => .00
[cta] => .00
[ptu] => .00
[pta] => .00
[sickHours] => .0000
[vacaHours] => .0000
[gross] => 4.50
)
[6] => Array
(
[empNum] => 17
[wksWrkd] => 2
[trcode] => 4
[appn] => 20000560005
[totalHours] => .00
[rate] => .00
[net] => .00
[overHours] => .25
[holidayHours] => 4.50
[overtimePay] => .00
[otherPay] => .00
[holidayPay] => .00
[ctu] => .00
[cta] => .00
[ptu] => .00
[pta] => .00
[sickHours] => .0000
[vacaHours] => .0000
[gross] => 4.50
)
)
What I have tried is two queries: one to get distinct empNums into an array and the other the array from above. I then did two foreach's but I don't know how to compare an element to itself and then go to the next element once that elements changes. I've also tried array_merge() and array_merge_recursive().