當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Calculator::getResult方法代碼示例

本文整理匯總了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();
開發者ID:aaron1986,項目名稱:TestGitHub,代碼行數:13,代碼來源:index.php

示例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();
開發者ID:bcahill,項目名稱:php_calculator,代碼行數:25,代碼來源:runner.php

示例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();
開發者ID:rahulpr,項目名稱:_rpr,代碼行數:9,代碼來源:index.php

示例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();
開發者ID:Addeuz,項目名稱:calculator,代碼行數:23,代碼來源:index.php

示例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>
開發者ID:hakudjin,項目名稱:ci_course1_2015,代碼行數:31,代碼來源:form.php

示例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());
開發者ID:LoveAndHappiness,項目名稱:php_oop_calculator,代碼行數:18,代碼來源:index.php


注:本文中的Calculator::getResult方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。