I currently have an array called contestData
that looks like this:
"BUNDLE" => array: [
"audio"=> array:[
"downloaded"=> [
"this_week"=> "365"
"today" => 987
]
"saved"=> [
"this_week"=> "56"
"today" => 193
]
]
"video"=> array:[
"downloaded"=> [
"this_week"=> "365"
"today" => 987
]
"saved"=> [
"this_week"=> "56"
"today" => 193
]
]
]
That shows this structure:
['BUNDLE']['audio']['downloaded']['this_week']
['BUNDLE']['video']['downloaded']['today']
['BUNDLE']['audio']['saved']['this_week']
['BUNDLE']['video']['saved']['today']
But now I’m trying to figure out how to, within a loop on this array, add the totals into a totals index called contestTotals
like this:
//total for bundles saved this week and today
['BUNDLE']['contestTotals']['saved']['this_week']
['BUNDLE']['contestTotals']['saved']['today']
//total for bundled downloaded this week and today
['BUNDLE']['contestTotals']['downloaded']['this_week']
['BUNDLE']['contestTotals']['downloaded']['today']
So at that point I’m not worried about the audio or video type but simply totaling for the bundle type
Here is the loop, but I’m unsure of how to properly add and save the totals in this way
foreach ($this->contestData as $type => &$typeData) {
if ($type !== 'contestTotals') {
foreach ($typeData as $bundleType => &$bundleTypeData) {
if(!isset($bundleTypeData['saved'])) $bundleTypeData['saved'] = [];
foreach ($this->interval as $intervals){
if(!isset($bundleTypeData['saved'][$intervals]))
$bundleTypeData['saved'][$intervals] = 0;
}
foreach ($this->interval as $intervals){
if(!isset($prdCatData['downloaded'][$intervals]))
$prdCatData['downloaded'][$intervals] = 0;
}
}
}
}