Why is this PHP warning (division by zero) being thrown? -
i receiving php warning 'division zero' due 1 of equations on site:
$vidlistapprate = (($vla['likes'] / $vla['views']) * 100;
after realized did not account fact variable $vla['views'] zero, changed code following, thinking eradicate warning:
$vidlistapprate = ($vla['views'] === 0) ? 0 : ($vla['likes'] / $vla['views']) * 100;
however, warning still appeared (note: $vla['views'] int) . tried replacing 0 string:
$vidlistapprate = ($vla['views'] === 0) ? 'n/a' : ($vla['likes'] / $vla['views']) * 100;
but still receive warning. know notices, warnings, , error messages in php error_log friends, how rewrite code appease warning?
an exact match expected here:
$vidlistapprate = ($vla['views'] === 0)...
maybe need:
$vidlistapprate = ($vla['views'] == 0)...
or:
$vidlistapprate = ($vla['views'] === '0')...
or:
$vidlistapprate = (!$vla['views'])...
Comments
Post a Comment