本文整理匯總了PHP中Calculator::subtraction方法的典型用法代碼示例。如果您正苦於以下問題:PHP Calculator::subtraction方法的具體用法?PHP Calculator::subtraction怎麽用?PHP Calculator::subtraction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Calculator
的用法示例。
在下文中一共展示了Calculator::subtraction方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Calculator
<?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: Calculator
<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();
// }
}
?>
<tr>
<td><?php