本文整理汇总了PHP中Math::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Math::add方法的具体用法?PHP Math::add怎么用?PHP Math::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Math
的用法示例。
在下文中一共展示了Math::add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testError
public function testError()
{
$math = new Math();
// no input
try {
$math->add();
} catch (\Exception $e) {
$this->assertEquals('Please provide numbers to add', $e->getMessage());
}
// no input
try {
$math->subtract();
} catch (\Exception $e) {
$this->assertEquals('Please provide numbers to subtract', $e->getMessage());
}
// no input
try {
$math->multiply();
} catch (\Exception $e) {
$this->assertEquals('Please provide numbers to multiply', $e->getMessage());
}
// no input
try {
$math->divide();
} catch (\Exception $e) {
$this->assertEquals('Please provide numbers to divide', $e->getMessage());
}
//invalid input
try {
$math->setA('adf');
} catch (\Exception $e) {
$this->assertEquals('Invalid input', $e->getMessage());
}
}
示例2: testBcMath
/**
* @requires extension bcmath
* @runInSeparateProcess
*/
public function testBcMath()
{
if (!extension_loaded('bcmath')) {
$this->markTestSkipped('The Bcmath extension is NOT loaded! You must enable it to run this test');
} elseif (extension_loaded('gmp')) {
$this->markTestSkipped('The GMP extension is loaded! You must remove it to run this test');
}
Math::add("3324234234234234234", "3324234234234234234");
$this->assertEquals(new BcEngine(), Math::getEngine());
}
示例3: age
{
$this->age += 1;
}
public function age()
{
return $this->age;
}
}
$joe = new Person();
$joe->haveBirthday();
$joe->haveBirthday();
echo ' joe ', $joe->age(), PHP_EOL;
$jane = new Person();
$jane->haveBirthday();
echo ' jane ', $jane->age(), PHP_EOL;
// '::' is the Scope Resolution Operator
//echo Person::$age;
class Math
{
//When you think 'static', think 'share;
public static function add()
{
return array_sum(func_get_args());
}
}
//$math = new Math;
//
//var_dump($math->add(1, 2, 3, 4, 5, 6, 7));
//This code is replaced with
echo ' math ', Math::add(1, 2, 3), PHP_EOL;
示例4: add
<?php
/**
* Created by PhpStorm.
* User: roger
* Date: 4/10/15
* Time: 17:46
*/
class Math
{
public function add()
{
return array_sum(func_get_args());
}
}
$math = new Math();
var_dump($math->add(1, 2, 3));
示例5: add
<?php
class Math
{
public static function add(...$nums)
{
return array_sum($nums);
}
}
echo Math::add(1, 2, 3);
示例6: var_dump
var_dump($f, $f2, $a);
// test map
$arr = array('fdjiefwf', '123');
Funt::map($arr, function ($k, $v) {
echo "{$k} -> {$v} \n";
});
Funt::map($arr, lambda('$k, $v -> print "$k ==> $v \\n"'));
$str = "abcdefg";
Funt::map($str, function ($ch) {
echo "{$ch} \n";
});
$arr = array(1, 2, 3, 4, 5);
echo Funt::reduce(function ($r, $k, $v) {
return $r + $v;
}, 1, $arr) . "\n";
echo Math::add(1, 2, 3, 4, 5, 6) . "\n";
echo Math::mul(1, 2, 3, 4, 5, 6) . "\n";
echo Math::pow(2, 3, 2) . "\n";
echo 2 ** 3 ** 2 . "\n";
function abc()
{
}
var_dump('abc') . "\n";
// PHP不支持“惰性特征”
// $arr = array(1/0, 3, 4);
// var_dump(count($arr));
// PHP的闭包“惰性特征”
$arr = function () {
return array(1 / 0);
};
// 使用PHP的yeild协同机制,可以实现类似nodejs的事件机制。
示例7: plus
/**
* Returns the sum of this number and the given one.
*
* The result has a scale of `max($this->scale, $that->scale)`.
*
* @param \Arki\Math\Number|int|float|string $that The number to add. Must be convertible to a BigDecimal.
*
* @return BigDecimal The result.
*
* @throws \ArithmeticError If the number is not valid, or is not convertible to a BigDecimal.
*/
public function plus($that)
{
$that = self::of($that);
if ($that->intVal->isZero() && $that->scale <= $this->scale) {
return $this;
}
$this->scaleValues($this, $that, $a, $b);
$value = Math::add($a, $b);
$scale = $this->scale > $that->scale ? $this->scale : $that->scale;
return new self(BigInteger::of($value), $scale);
}
示例8: autoloader
<?php
function autoloader($class)
{
include 'classes/' . $class . '.php';
}
spl_autoload_register('autoloader');
$math = new Math();
echo $math->add(2, 3);
示例9: testAdd
public function testAdd()
{
$math = new Math();
$this->assertEquals(3, $math->add(1, 2));
$this->assertEquals(10, $math->add(3, 7));
}
示例10: add
<?php
//most of the time statics are not the right choice
//static something if you need to have it shared across all similar classes
//public statics are namespaced but globally accessible functions
class Math
{
//add() doesn't need to be dynamic
//makes it a global function without requiring a specific instance
public static function add(...$nums)
{
//have to be careful to not call other functions since this is static
return array_sum($nums);
}
}
echo Math::add(1, 2, 3, 4);