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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -