0

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.

mracer164
  • 44
  • 8
  • 1
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 13 '17 at 12:36
  • I am aware of that, used wrong word here, corrected. – mracer164 Sep 13 '17 at 12:38
  • Without more code or context we're not going to be able to help you. What you've posted has no obvious errors or problems. – Jay Blanchard Sep 13 '17 at 12:42
  • Added all relevant code. – mracer164 Sep 13 '17 at 13:09

0 Answers0