当前位置: 首页>>代码示例>>PHP>>正文


PHP Calculator::subtract方法代码示例

本文整理汇总了PHP中Calculator::subtract方法的典型用法代码示例。如果您正苦于以下问题:PHP Calculator::subtract方法的具体用法?PHP Calculator::subtract怎么用?PHP Calculator::subtract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Calculator的用法示例。


在下文中一共展示了Calculator::subtract方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testSubtract

 public function testSubtract()
 {
     $calc = new Calculator();
     $difference = $calc->subtract(5, 2);
     $this->assertEquals(3, $difference);
     //check if 5 - 2 is equal to 3
 }
开发者ID:sampletestorg1,项目名称:sample_php,代码行数:7,代码来源:calculator_test.php

示例2: shouldSubtractTwoNumbers

 /**
  * @test
  */
 public function shouldSubtractTwoNumbers()
 {
     // given
     $calculator = new \Calculator();
     // when
     $result = $calculator->subtract(3, 2);
     // then
     $this->assertEquals(1, $result);
 }
开发者ID:DevSKiller,项目名称:devskiller-sample-php-calculator,代码行数:12,代码来源:CalculatorTest.php

示例3: shouldSubtractTwoNumbers

 /**
  * @test
  */
 public function shouldSubtractTwoNumbers()
 {
     // given
     $a = rand(0, 100);
     $b = rand(0, 100);
     $calculator = new \Calculator();
     // when
     $result = $calculator->subtract($a, $b);
     // then
     $this->assertEquals($a - $b, $result);
 }
开发者ID:DevSKiller,项目名称:devskiller-sample-php-calculator,代码行数:14,代码来源:RandomNumbersTest.php

示例4: __construct

    public function __construct($a, $b)
    {
        $this->_a = $a;
        $this->_b = $b;
    }
    public function add()
    {
        return $this->_a + $this->_b;
    }
    public function subtract()
    {
        return $this->_a - $this->_b;
    }
    public function multiply()
    {
        return $this->_a * $this->_b;
    }
    public function divide()
    {
        return $this->_a / $this->_b;
    }
}
$mycalc = new Calculator(12, 6);
echo $mycalc->add() . "<br>";
// Displays 18
echo $mycalc->multiply() . "<br>";
// Displays 72
echo $mycalc->subtract() . "<br>";
// Displays 6
echo $mycalc->divide() . "<br>";
// Displays 2
开发者ID:kbalog,项目名称:web-programming,代码行数:31,代码来源:exercise6.php

示例5: add

    {
        $this->_val1 = $val1;
        $this->_val2 = $val2;
    }
    public function add()
    {
        return $this->_val1 + $this->_val2;
    }
    public function subtract()
    {
        return $this->_val1 - $this->_val2;
    }
    public function multiply()
    {
        return $this->_val1 * $this->_val2;
    }
    public function divide()
    {
        return $this->_val1 / $this->_val2;
    }
}
$calc = new Calculator(3, 4);
echo "<p>3 + 4 = " . $calc->add() . "</p>";
echo "<p>3 - 4 = " . $calc->subtract() . "</p>";
echo "<p>3 * 4 = " . $calc->multiply() . "</p>";
echo "<p>3 / 4 = " . $calc->divide() . "</p>";
?>

  </body>
</html>
开发者ID:hoiwanjohnlouis,项目名称:eclipsePrototyping,代码行数:30,代码来源:exercise1.php


注:本文中的Calculator::subtract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。