I've got this multi-dimensional array (if that's what it is called) of customers and inside the customer is his items, and the fee for those items.. However, I need to get all the fee's from the items and sum them for the customer. Array Structure
Array
(
[6bb728] => Array
(
[TitleName] => Sir Isaac
[Surname] => Newton
[sum] =>
[id] => 6bb728
[items] => Array
(
[29] => Array
(
[AssignedTo] => 6bb728
[Number] => 03-014
[MFee] => 103.5
)
)
)
The sum key should contain the sum of the items fees. Which brings me on to my question: Is there any efficient way of getting the sum of one key which is present in a multi dimensional array?
I've tried a quadruple foreach which sent my computer into a loop (there are hundreds of customers and it'd have to do so many loops)
foreach($customers as $value) {
foreach($value as $value1){
foreach($value1['items'] as $value2) {
foreach($value2 as $value3) {
$customers[$value3['AssignedTo']]['Fee'] += $value3['MFee'];
}
}
}
}