我收到警告“除以零”
这是代码
<p class='text-alert' id ="greet" align="left">Kill Death Ratio : <?php
$kd = $data['kills'] / $data['deaths'];
echo round($kd, 2);
?></p>
我想我只有在杀戮和死亡价值均为零时才能得到它 有没有可能的解决方案
答案 0 :(得分:2)
只需在分区前添加if语句
<p class='text-alert' id ="greet" align="left">Kill Death Ratio : <?php
if ($data['deaths'] != 0){
$kd = $data['kills'] / $data['deaths'];
echo round($kd, 2);
}
else{
// Some other code which you want to run in case of zero
}
?></p>