public $num_2; public $oper; public $result; function __construct($num_1 = '', $num_2 = '', $oper = '') { $this->num_1 = $num_1; $this->num_2 = $num_2; $this->oper = $oper; } function calculate() { switch ($this->oper) { case '+': $this->result = $this->num_1 + $this->num_2; break; case '-': $this->result = $this->num_1 - $this->num_2; break; case '*': $this->result = $this->num_1 * $this->num_2; break; case '/': $this->result = $this->num_1 / $this->num_2; break; } return $this->result; } } $way = new JiSuan($_GET['Num_1'], $_GET['Num_2'], $_GET['oper']); $result = $way->calculate(); echo '计算结果:' . $result;
$jg = $one * $two; echo $jg; } static function chu() { $one = $_POST['one']; $two = $_POST['two']; if ($two == 0) { echo "除数不能为0"; } else { $jg = $one / $two; echo $jg; } } } $jisuan_1 = new JiSuan(); $fuhao = $_POST['fuhao']; switch ($fuhao) { case '+': echo "计算结果等于"; $jisuan_1->jia(); break; case '-': echo "计算结果等于"; $jisuan_1->jian(); break; case '*': echo "计算结果等于"; $jisuan_1->cheng(); break; case '/':