警告:php副本中除零错误


Warning: Division by zero Error in php duplicate

我在php中得到这个错误,我不太明白为什么会发生。有人能解释一下为什么这是一个错误吗?我是php的初学者,所以请原谅我。任何形式的反馈将非常感激。

<!DOCTYPE html>
 <head> 
 <title> Distance </title>
   </head>
   <body>
   <?php

 function distance($lat,$lng,$d){
   $distannce = ($lat - $lng) / $d;
   return $distannce;
   }
$stand = distance(isset($_POST['val']),isset($_POST['value']),isset($_POST['dist']));
  ?>
    <form method = "post">

   <input type="checkbox" name="dtLatLng_Lat"  checked="checked"  />
    <label for="dtLatLng_Lat"> Latitude </label>&nbsp &nbsp &nbsp;
  base
  <input type="text"name="val"  size ="6"   style="width:60px"; /> 
    dist
    <input type="text"name="dis" id="dis" size = "1"; /> 
    <label for="dis">  </label>
    <br>
  <input type="checkbox" name="dtLatLng" id="dtLatLng" checked="checked" />
   <label for="dtLatLng"> Longitude </label>&nbsp &nbsp;
   base
   <input type="text" name="value" id="dtvalue" size ="6" style="width:60px";/> 
    <label for="dtvalue"> </label>&nbsp;
dist
   <input type="text"name="dist" id="dtval" size ="1"; /> 
   <br>
     <input type="submit" name="submit" value="Submit" />
    </form>
   </body>
     </html>

在你的代码中$d变为零,因为它显示"警告:除零错误在php重复"

试试这个

function distance($lat,$lng,$d){
   if($d != 0)
   {
       $distannce = ($lat - $lng) / $d;
   }
   else
   {
       $distannce = 0;
   }
   return $distannce;
}