I'm not entirely sure what you are trying to do, it would be quite nice to see the array you are passing into this. Either way the undefined index error is being produced because you are trying to access the array key $key when it does not exist.
From what I can work out, you just want to add the total to a key off your array if that key is set? If the key is not set then you want to create that key and set its value equal to the current total. At least that is my understanding of what you want.
So what you have done is almost correct except you try to access an index that hasn't been set when your conditional fails.
if (!isset($array[$key])) {
$array[$key] = $total;
} else {
$array[$key] += $total;
}
The above should fix your error, there probably are a few cleaner solutions but without knowing more information about the contents of the array and the purpose of the script it is hard to say what is the best method to use.