I've tried about 20 different ideas for this and I think I've gone in so many circles I can't remember where I started. I'm sure this is a simple one too.
I have an array;
Array
(
[0] => Array
(
[employee] => 15
[first_name] => Person1
[surname] => Person1
[totaltime] => 183.75
[type] => 0
)
[1] => Array
(
[employee] => 15
[first_name] => Person1
[surname] => Person1
[totaltime] => 64.50
[type] => 1
)
[2] => Array
(
[employee] => 23
[first_name] => Person2
[surname] => Person2
[totaltime] => 2.00
[type] => 0
)
[3] => Array
(
[employee] => 51
[first_name] => Person3
[surname] => Person3
[totaltime] => 119.25
[type] => 0
)
[4] => Array
(
[employee] => 59
[first_name] => Person4
[surname] => Person4
[totaltime] => 170.75
[type] => 0
)
)
I need to merge the elements where the employee number is the same and add the totaltime elements to new keys based on the type. This is what I mean.
Array
(
[0] => Array
(
[employee] => 15
[first_name] => Person1
[surname] => Person1
[totaltime_type_0] => 183.75
[totaltime_type_1] => 64.50
)
[1] => Array
(
[employee] => 23
[first_name] => Person2
[surname] => Person2
[totaltime_type_0] => 2.00
[totaltime_type_1] => 0
)
[2] => Array
(
[employee] => 51
[first_name] => Person3
[surname] => Person3
[totaltime_type_0] => 119.25
[totaltime_type_1] => 0
)
[3] => Array
(
[employee] => 59
[first_name] => Person4
[surname] => Person4
[totaltime_type_0] => 170.75
[totaltime_type_1] => 0
)
)
I could do this at the query level but the SQL to create the original array is so complex I'd rather only maintain the one version of it.
Any suggestions on the best approach would really help me get back on track with this. And will be REALLY appreciated.