Search the Community
Showing results for tags 'map'.
-
I am getting the exact same error over and over again, and I have no idea why: Consider the code function calculateResults($pollObj) { $conn = null; $stmt = null; $rs = null; $total = 0; global $resultsCalcArray; try { $pollId = stripHTML(cleanXSS($pollObj->id)); $conn = new PDO(DB_CONNECTION_STR, MYSQL_DB_USER, MYSQL_DB_PASSWORD, MYSQL_DB_PDO_OPTIONS); $stmt = $conn->prepare(RESULTS_SQL); $stmt->execute([$pollId, $pollId, $pollId]); $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); if (!is_null($rs)) { foreach ($rs as $row) { if (!empty($row['kount'])) { $total += (int) $row['kount']; array_push($resultsCalcArray, $row['kount']); } } } $_SESSION['total'] = $total; if ($total > 0) { // TO PREVENT DIVIDE BY ZERO ERROR $resultsCalcArray = array_map(function($votes) { return round($votes / $total) * 100; }, $resultsCalcArray); } } catch (Exception $e) { $msg = ERROR_MESSAGE . ' calculateResults() ' . date('Y-m-d H:i:s') . ' ' . $e->getMessage(); toLogDB($msg); error_log($msg, 0); throw $e; $hasErrors = true; } finally { if (!is_null($rs)) { $rs = null; } if (!is_null($stmt)) { $stmt = null; } if (!is_null($conn)) { $conn = null; } } } I honestly don't know what I did wrong here, but it is completely failing the entire code within the function inside array_map(), and I have no idea why. Help appreciated and needed. Thanks