本文整理汇总了PHP中Calculator::sum方法的典型用法代码示例。如果您正苦于以下问题:PHP Calculator::sum方法的具体用法?PHP Calculator::sum怎么用?PHP Calculator::sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Calculator
的用法示例。
在下文中一共展示了Calculator::sum方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testThatSumWorks
public function testThatSumWorks()
{
$calculator = new Calculator();
$this->assertEquals(2, $calculator->sum(1, 1));
}
示例2: testSum
public function testSum()
{
$cal = new Calculator();
$this->assertEquals(4, $cal->sum(2, 2));
}
示例3: Calculator
<?php
Logger::log('Start');
$param1 = (int) (isset($_POST['param1']) ? $_POST['param1'] : $_GET['param1']);
$param2 = (int) (isset($_POST['param2']) ? $_POST['param2'] : $_GET['param2']);
Logger::log('Got params: %s and %s', [$param1, $param2]);
$calculator = new Calculator();
$result = $calculator->sum($param1, $param2);
echo '<div><b>Program "Calculator"</b><br><br>' . $param1 . ' + ' . $param2 . ' = <b>' . $result . '</b></div>';
Logger::log('Finish');
示例4:
margin: 0 auto;
}
.container{
margin-top: 70px;
}
</style>
</head>
<body>
<div class="container max-960">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12"></div>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="panel-heading"><h3>Calculation = <?php
echo $cal->sum();
?>
</h3></div>
<form role="form">
<div class="form-group">
<label for="val1">Value 1</label>
<input type="number" name="val1" class="form-control" placeholder=" Enter number">
</div>
<select class="form-control" name="operator">
<?php
$cal->get_Operator();
?>
</select>
<div class="form-group">
<label for="val2">Value 2</label>
<input type="number" name="val2" class="form-control" placeholder=" Enter number">
示例5: sum
<?php
class Calculator
{
private $number;
public function sum($number)
{
$this->number = $number;
$odd = 0;
$even = 0;
for ($i = 0; $i <= $this->number; $i++) {
if ($i % 2 == 1) {
$odd = $odd + $i;
} else {
$even = $even + $i;
}
}
echo "sum of odd number between 1 to " . $this->number . "is" . $odd . "<br />";
echo "sum of even number between 1 to " . $this->number . "is " . $even;
}
}
$calc = new Calculator();
$calc->sum(100);
示例6: __invoke
public function __invoke()
{
$input = file_get_contents(__DIR__ . "/../../input/Day12/Puzzle1");
$calculator = new Calculator();
$this->write("Total: " . $calculator->sum($input));
}
示例7: Calculator
<?php
require_once 'lib/Calculator.php';
$calc = new Calculator();
echo $calc->sum(2, 2);