本文整理汇总了PHP中Calculator::getResult方法的典型用法代码示例。如果您正苦于以下问题:PHP Calculator::getResult方法的具体用法?PHP Calculator::getResult怎么用?PHP Calculator::getResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Calculator
的用法示例。
在下文中一共展示了Calculator::getResult方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Calculator
<?php
require_once 'init.php';
$c = new Calculator();
$c->setOperation(new Adder());
$c->calculate(10, 50);
$c->setOperation(new Subtractor());
$c->calculate(30);
$c->setOperation(new Multiplier());
$c->calculate(5);
$c->setOperation(new Divider());
$c->calculate(2);
echo $c->getResult();
示例2: Calculator
<?php
require_once 'calculator.php';
$variable = $_GET['data_array'];
$calculator = new Calculator($variable);
$calculator->splitString();
$calculator->num_array = $calculator->breakDownArray($calculator->num_array, 3);
$calculator->calculateEquation($calculator->num_array);
//check first
//if one contains ^ run the exponent run function and replace the last value of the previous array and replace the first index of the next array
//then delete that array that holds one value
//check second
//continue this for / and *
//still delete the evaluated arrays that would only hold one number
//check last
//lastly do + or -
//flatten end result and return as a number
// then if one contains / or *
// run function and store that value in that array
//then if one contains + or -
//run function
//handle how many operators are in the string
//currently only handling one operator
$calculator->roundNumber($calculator->result);
echo $calculator->getResult();
示例3: Calculator
<?php
require 'class/operatorInterface.php';
require 'class/Calculator.php';
require 'class/Adder.php';
$calcObj = new Calculator();
$calcObj->setOperation(new Adder());
$calcObj->calculate(1, 2, 3, 4, 5);
echo $calcObj->getResult();
示例4: Calculator
<?php
//require_once 'classes/calculator.php';
//require_once 'classes/operatorInterface.php';
//require_once 'classes/adder.php';
//require_once 'classes/subtractor.php';
//require_once 'classes/multiplier.php';
//require_once 'classes/divider.php';
require_once 'init.php';
$calc = new Calculator();
$calc->setOperation(new Adder());
$calc->calculate(50, 50);
//100
$calc->setOperation(new Subtractor());
$calc->calculate(30);
//70
$calc->setOperation(new Multiplier());
$calc->calculate(3);
//210
$calc->setOperation(new Divider());
$calc->calculate(2);
//105
echo $calc->getResult();
示例5: Calculator
<body>
<form method="post">
<input type="number" name="number1">
<input type="text" name="operator">
<input type="number" name="number2">
<input type="submit" name="calculator" value="Calculate">
</form>
<?php
$calculator1 = new Calculator();
if (isset($_POST['calculator'])) {
$number1 = $_POST['number1'];
$number2 = $_POST['number2'];
$operator = $_POST["operator"];
if ($operator == "+") {
$calculator1->add($number1, $number2);
echo $calculator1->getResult();
} elseif ($operator == "-") {
$calculator1->sub($number1, $number2);
echo $calculator1->getResult();
} elseif ($operator == "/") {
$calculator1->div($number1, $number2);
echo $calculator1->getResult();
} elseif ($operator == "*") {
$calculator1->mul($number1, $number2);
echo $calculator1->getResult();
} else {
echo "Invalid operator";
}
}
?>
</body>
示例6: Calculator
<?php
require_once '/vendor/autoload.php';
$multi = new Calculator();
$multi->setOperation(new Multiplication());
$multi->setOperands(3, 5);
$multi->calculate();
var_dump($multi->getResult());
$add = new Calculator();
$add->setOperation(new Addition());
$add->setOperands(12, 14);
$add->calculate();
var_dump($add->getResult());
$subtract = new Calculator();
$subtract->setOperation(new Subtraction());
$subtract->setOperands(15, 6);
$subtract->calculate();
var_dump($subtract->getResult());