当前位置: 首页>>代码示例>>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;未经允许,请勿转载。