PHP Associative Array, same code on same level doesn't work
<p>I have a really strange problem over here. Sorry for the ugly redundant parts, but it is only for prototyping. In both blocks I calculate the seconds of the given worktime. The first block was the first version and worked, but wasn't that robust. So the second block solved the robustness problem. 
The important part is
<code>$hours[$row["gamemaster"]] = $hours[$row["gamemaster"]] + $worktime;</code></p>

<p>In both blocks the integer $worktime is in seconds. But now the problem is, that in the second block the sum of the worktime doesn't work. It's on the same level, and there are no changes at other parts of the code.</p>

<p>The expected value is the sum of the working hours for each gamemaster. In the first block the printed value is the time as expected and in the second block nothing happens. And my big question mark is, that the calculation of the sum is exactly the same and only the calculation of the worktime before is different. And if I add only normal integers in the second block like <code>$hours[$row["gamemaster"]] = $hours[$row["gamemaster"]] + 1;</code> nothing happens, but for the first block, also something strange like <code>$hours[$row["gamemaster"]] = $hours[$row["gamemaster"]] + "p";</code> worked. </p>

<p>first block:</p>

<pre><code>if($row["no_game"]==0) {
    $worktime = strtotime($row["additional"]);
    $worktime = $worktime + 5400;

    $hours[$row["gamemaster"]] = $hours[$row["gamemaster"]] + $worktime;
  }
  else {
    $worktime = strtotime($row["additional"]);

    $hours[$row["gamemaster"]] = $hours[$row["gamemaster"]] + $worktime;
  }
</code></pre>

<p>output first block for $hours: <br>
[key]:[value] <br>
Felix:8778047400 <br>
Marie:2926018800 <br></p>

<p>second block:</p>

<pre><code>  if($row["no_game"]==0) {
    $str_time = $row["additional"];
    $str_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $str_time);
    sscanf($str_time, "%d:%d:%d", $hours, $minutes, $seconds);
    $time_seconds = $hours * 3600 + $minutes * 60 + $seconds;
    $worktime = $time_seconds + 5400;

    $hours[$row["gamemaster"]] = $hours[$row["gamemaster"]] + $worktime;
  }
  else {
    $str_time = $row["additional"];
    $str_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $str_time);
    sscanf($str_time, "%d:%d:%d", $hours, $minutes, $seconds);
    $worktime = $hours * 3600 + $minutes * 60 + $seconds;

    $hours[$row["gamemaster"]] = $hours[$row["gamemaster"]] + $worktime;
  }
</code></pre>

<p>output second block for $hours:
Nothing, like nothing is written in the array</p>

<p>Update 1:
I reduce the code of the second block to</p>

<pre><code>    $str_time = $row["additional"];
    $str_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $str_time);
    sscanf($str_time, "%d:%d:%d", $hours, $minutes, $seconds);
    $time_seconds = $hours * 3600 + $minutes * 60 + $seconds;
    $worktime = $time_seconds + 5400;Update 1:
</code></pre>

<p>I reduce the code of the second block to</p>

<pre><code>    $str_time = $row["additional"];
    $str_time = preg_replace("/^([\d]{1,2})\:([\d]{2})$/", "00:$1:$2", $str_time);
    sscanf($str_time, "%d:%d:%d", $hours, $minutes, $seconds);
    $time_seconds = $hours * 3600 + $minutes * 60 + $seconds;
    $worktime = $time_seconds + 5400;
    $hours[$row["gamemaster"]] = $hours[$row["gamemaster"]] + $worktime;
</code></pre>

<p>There are 8 iterations over the dataset and the output for $worktime afer each iteration is: <br>
1: 7200 <br>
2: 5400 <br>
3: 5400 <br>
4: 7200 <br>
5: 7200 <br>
6: 7200 <br>
7: 5400 <br>
8: 5400 <br>
<br>
But there is still no entry in $hours.</p>