I have a code like this :
foreach ($this->dayCounts as $activity => $day) {
foreach ($day as $date => $columns) {
foreach ($columns as $column => $value) {
@$this->totalCounts[$activity][$column] += $value;
}
}
}
Basically it is adding daily values for each activity and each column to get total counts. I am using '@'
operator here not to throw the warning. Is there any modification that I can make which will remove the '@'
operator as it is not a good practice to use it.
The error I am getting is Undefined index
with the column and activity name.
Warnings you're supressing might be caused by non-existent indexes in $this->totalCounts array. You can avoid them by explicitely initializing fields of this array.
Replace
@$this->totalCounts[$activity][$column] += $value;
with
if (!isset($this->totalCounts[$activity][$column])) {
$this->totalCounts[$activity][$column] = 0;
}
$this->totalCounts[$activity] += $value;