示例#1
0
<?php

require 'calculator.php';
$obj = new Calculator();
if (isset($_POST['btn'])) {
    $first_number = $_POST['first_number'];
    $last_number = $_POST['last_number'];
    $btn = $_POST['btn'];
    if ($btn == '+') {
        $result = $obj->addition($first_number, $last_number);
    } else {
        if ($btn == '-') {
            $result = $obj->subtraction($first_number, $last_number);
        } else {
            if ($btn == '*') {
                $result = $obj->multiplication($first_number, $last_number);
            } else {
                if ($btn == '/') {
                    $result = $obj->division($first_number, $last_number);
                } else {
                    if ($btn == '%') {
                        $result = $obj->reminder($first_number, $last_number);
                    }
                }
            }
        }
    }
}
?>
<html>
    <head>
示例#2
0
                <div class="btn-group">
                    <button class="btn btn-default" type="submit" name="btn" value="+">+</button>
                    <button class="btn btn-default" type="submit" name="btn" value="-">-</button>
                    <button class="btn btn-default" type="submit" name="btn" value="*">*</button>
                    <button class="btn btn-default" type="submit" name="btn" value="/">/</button>
                </div>
            </td>
        </tr>
        <!--Checks whether buttons have been clicked and calls the function according to btn clicked-->
        <?php 
$obj = new Calculator();
if (isset($_POST['btn'])) {
    $first_number = $_POST['first_number'];
    $second_number = $_POST['second_number'];
    if ($_POST['btn'] == '+') {
        $result = $obj->addition($first_number, $second_number);
    }
    if ($_POST['btn'] == '-') {
        $result = $obj->subtraction($first_number, $second_number);
    }
    if ($_POST['btn'] == '*') {
        $result = $obj->multiply($first_number, $second_number);
    }
    if ($_POST['btn'] == '/') {
        $result = $obj->division($first_number, $second_number);
    }
    //            if($first_number==0 or $second_number==0){
    //                $result= $obj->nothing();
    //            }
}
?>