本文实例为大家分享了PHP实现简单计算器的具体代码,供大家参考,具体内容如下

caculator.php

<html>
<head>
 
</head>
<body>
 
<"data1"];
  $data2 = $_POST["data2"];
  $fuhao = $_POST["fuhao"];
  $result = "";
 
  echo $data1;
  echo $data2;
  echo $fuhao;
  echo $result;
 
 
  if ($fuhao == '+') {
    $result = $data1 + $data2;
  } else if ($fuhao == '-') {
    $result = $data1 - $data2;
  } else if ($fuhao == '*') {
    $result = $data1 * $data2;
  } else if ($fuhao == '/') {
    $result = $data1 / $data2;
  }
} else {
  $data1 = "";
  $data2 = "";
  $fuhao = "";
  $result = "";
}
 
"caculator.php" method="post">
  <input type="text" name="data1" value="<"/>
  <select name="fuhao">
 
    <option value="+"
        <"+") {
          echo 'selected="selected"';
        } "-"
        <"-") {
          echo 'selected="selected"';
        } "*"
        <"*") {
          echo 'selected="selected"';
        } "/"
    <"/") {
      echo 'selected="selected"';
    } "text" name="data2" value="<"/>
  <input type="submit" value="="/>
  <input name="result" type="text" value="<"/>
  <input type="reset"/>
 
</form>
 
 
</body>
</html>

运行结果:

PHP实现简单的计算器

PHP实现简单的计算器

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com