Thursday 4 April 2019

php - Division by zero error in votes

This should work for you:


(It's testing if $total_voting is zero and returns in this case false)


function percent($liked, $total_voting) {
if($total_voting == 0)
return false;
$liked = (int)$liked;
$total_voting = (int)$total_voting;
return ceil(($liked/$total_voting)*100);
}

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...