I've been searching for this and can't find it, though it's hard to put in to words so I apologize if it's covered elsewhere.
I have an API call I make that gives me this. This is shifts worked on a given date and there is an array for each shift. This is what one looks like.
$lastMon = array{
date => $date
hours => 8
worker => mjones
etc
}
Now I want to take the recruiter value and the hours value and create another array that looks like this
$lastMonData = array{
key for each $lastMon->recruiter => sum of all $lastMon->hours where recruiter is unique
total += $lastMon->hours
}
Basically, I have a bunch of shifts I extract from this system and turn it in to arrays and insert some keys I pull from other parts of the system. I then need an array by date that contains the total hours worked for all the shifts that day, and then a key for each unique name in the recruiter key that adds up the hours mentioned in the same array. I hope this makes sense.
EDIT:
Here is an example
SimpleXMLElement Object
(
[orderId] => 4000262
[status] => filled
[shiftStartTime] => 2018-12-10T07:30:00
[shiftEndTime] => 2018-12-10T12:30:00
[tempId] => 80231
[firstName] => SimpleXMLElement Object
(
)
[lastName] => SimpleXMLElement Object
(
)
[clientId] => 42642
[clientName] => SimpleXMLElement Object
(
)
[regionName] => SimpleXMLElement Object
(
)
[orderSpecialty] => School
[orderCertification] => RN
[floor] => SimpleXMLElement Object
(
)
[shiftNumber] => 1
[note] => SimpleXMLElement Object
(
)
[payrollNumber] => SimpleXMLElement Object
(
)
[lessLunchMin] => SimpleXMLElement Object
(
)
[dateTimeCreated] => 2018-08-17T09:33:43
[takenBy] => 592
[bookedByUserId] => 592
[orderTypeId] => 1
[orderType] => SimpleXMLElement Object
(
)
[city] => Holmdel
[state] => NJ
[zipCode] => 07733
[orderSourceID] => SimpleXMLElement Object
(
)
[orderSourceName] => SimpleXMLElement Object
(
)
[lt_orderID] => 13643
[dateTimeModified] => 2018-08-17T09:33:43
[recruiter] => John Smith
[hours] => 05
)
SimpleXMLElement Object
(
[orderId] => 4002473
[status] => filled
[shiftStartTime] => 2018-12-10T09:00:00
[shiftEndTime] => 2018-12-10T13:30:00
[tempId] => 1397353
[firstName] => SimpleXMLElement Object
(
)
[lastName] => SimpleXMLElement Object
(
)
[clientId] => 47597
[clientName] => SimpleXMLElement Object
(
)
[regionName] => SimpleXMLElement Object
(
)
[orderSpecialty] => School
[orderCertification] => RN
[floor] => SimpleXMLElement Object
(
)
[shiftNumber] => 1
[note] => SimpleXMLElement Object
(
)
[payrollNumber] => SimpleXMLElement Object
(
)
[lessLunchMin] => SimpleXMLElement Object
(
)
[dateTimeCreated] => 2018-08-20T08:53:23
[takenBy] => 592
[bookedByUserId] => 592
[orderTypeId] => 1
[orderType] => SimpleXMLElement Object
(
)
[city] => Tinton Falls
[state] => NJ
[zipCode] => 07701
[orderSourceID] => SimpleXMLElement Object
(
)
[orderSourceName] => SimpleXMLElement Object
(
)
[lt_orderID] => 0
[dateTimeModified] => 2018-08-20T10:05:33
[recruiter] => Mike Jones
[hours] => 04
)
I need to take the recruiter value and make those in to keys in a new array. Some repeat, so I would only want to take the unique ones. Then, the hours value in this array would be the value for the recruiter name key in the new array.
So this would then look like
$lastMon = array{
Mike Jones => 4
John Smith => 5
Total => 9
}