I got the following code:
$hostUptimesSum = [];
foreach($hostIDs as &$hostID)
{
$hostUptimeDetailsQuery = "some query";
$resultHostUptimeDetails = mysql_query($hostUptimeDetailsQuery);
$rowHostUptimeDetails = mysql_fetch_assoc($resultHostUptimeDetails);
$totalTime = $rowHostUptimeDetails['UP_T'] + $rowHostUptimeDetails['DOWN_T'] + $rowHostUptimeDetails['UNREACHABLE_T'] + $rowHostUptimeDetails['UNDETERMINED_T'] + $rowHostUptimeDetails['MAINTENANCE_T'];
array_push($hostUptimes, $rowHostUptimeDetails);
$hostUptimesSum['UP_A'] += $rowHostUptimeDetails['UP_A'];
$hostUptimesSum['UP_T'] += $rowHostUptimeDetails['UP_T'];
$hostUptimesSum['DOWN_A'] += $rowHostUptimeDetails['DOWN_A'];
$hostUptimesSum['DOWN_T'] += $rowHostUptimeDetails['DOWN_T'];
$hostUptimesSum['UNREACHABLE_A'] += $rowHostUptimeDetails['UNREACHABLE_A'];
$hostUptimesSum['UNREACHABLE_T'] += $rowHostUptimeDetails['UNREACHABLE_T'];
$hostUptimesSum['UNDETERMINED_T'] += $rowHostUptimeDetails['UNDETERMINED_T'];
$hostUptimesSum['MAINTENANCE_T'] += $rowHostUptimeDetails['MAINTENANCE_T'];
$hostUptimesSum['TOTAL'] += $totalTime;
array_push($values, array($hostID['host_name'],
round($rowHostUptimeDetails['UP_T']/$totalTime*100,2)."%",$rowHostUptimeDetails['UP_A'],
round($rowHostUptimeDetails['DOWN_T']/$totalTime*100,2)."%",
$rowHostUptimeDetails['DOWN_A']
,round($rowHostUptimeDetails['UNREACHABLE_T']/$totalTime*100,2)."%",
$rowHostUptimeDetails['UNREACHABLE_A'],
round($rowHostUptimeDetails['MAINTENANCE_T']/$totalTime*100,2)."%",
round($rowHostUptimeDetails['UNDETERMINED_T']/$totalTime*100,2)."%",));
}
var_dump($hostUptimesSum);
$data = array(
'UP' => $hostUptimesSum['UP_T'],
'DOWN' => $hostUptimesSum['DOWN_T'],
'UNREACHABLE' => $hostUptimesSum['UNREACHABLE_T'],
'SCHEDULED DOWNTIME' => $hostUptimesSum['MAINTENANCE_T'],
'UNDETERMINED' => $hostUptimesSum['UNDETERMINED_T']
);
The $hostUptimesSum
array is declared outside the foreach
loop. If I perform var_dump on the array inside foreach
loop I can see values adding up correctly but when I call var_dump outside the loop I get nothing.
I am completely out of ideas at the moment.
Edit: I added all the code related to this particular array.