本文整理汇总了PHP中Calculator::addition方法的典型用法代码示例。如果您正苦于以下问题:PHP Calculator::addition方法的具体用法?PHP Calculator::addition怎么用?PHP Calculator::addition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Calculator
的用法示例。
在下文中一共展示了Calculator::addition方法的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
<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();
// }
}
?>