I created a for(…) cycle where I plan to go through the values of an array and use those values to accumulate them in another array, but I’m getting a notice from Apache that says Notice: Undefined offset: …. The code I’m using is something like this:
for ($a=0;$a<count($original_array);$a++){
$accumulate_array[$a] += $original_array[$a]
}
I think the notice comes from the part where I do the “+=” because it’s doing something like:
$accumulate_array[$a] = $accumulate_array[$a] + $original_array[$a]
And it’s referencing a value that still doesn’t exist, I think.
You’re correct, the notice is because of this line:
Because it expands to:
And
$accumulate_array[$a]is undefined, while it’s trying to grab that value. So, if you’re creating a running sum, you probably want to initialize it to zero, like so: