I'm getting a division by zero error on this line of code:
$ratio['p{W}'] = ($ratio['{W}'] === 0) ? 0 : ($colorTotal === 0) ? 0 : ($ratio['{W}'] / $colorTotal) * 100;
I've tested the above with:
echo '$ratio[{W}]:'.$ratio['{W}'].', $colorTotal:'.$colorTotal;
if($ratio['{W}'] === 0) {
echo('$ratio[{W}]: zero');
}
else {
echo('$ratio[{W}]: not zero');
}
if($colorTotal === 0) {
echo('$colorTotal: zero');
}
else {
echo('$colorTotal: not zero');
}
and the results are:
[01-Jul-2015 17:40:26 UTC] $ratio[{W}]:0, $colorTotal:0
[01-Jul-2015 17:40:26 UTC] $ratio[{W}]: zero
[01-Jul-2015 17:40:26 UTC] $colorTotal: zero
It seems I should never reach this point ($ratio['{W}'] / $colorTotal
) in the code since the previous criteria is 0 in the checks but it seems to reach it? How can I prevent this error?