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


PHP Math::add方法代码示例

本文整理汇总了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());
     }
 }
开发者ID:soycaringal,项目名称:gae-test,代码行数:34,代码来源:function.php

示例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());
 }
开发者ID:bitpay,项目名称:php-client,代码行数:14,代码来源:MathTest.php

示例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;
开发者ID:ldmcdaniel,项目名称:OOBootcamp,代码行数:30,代码来源:sandc.php

示例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));
开发者ID:rogermelich,项目名称:Laracast_Exercicis,代码行数:17,代码来源:ex.php

示例5: add

<?php

class Math
{
    public static function add(...$nums)
    {
        return array_sum($nums);
    }
}
echo Math::add(1, 2, 3);
开发者ID:alexbonavila,项目名称:PHP_Exercicis,代码行数:10,代码来源:ex.php

示例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的事件机制。
开发者ID:kitech,项目名称:triline,代码行数:31,代码来源:functional.php

示例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);
 }
开发者ID:arkitekto,项目名称:math,代码行数:22,代码来源:BigDecimal.php

示例8: autoloader

<?php

function autoloader($class)
{
    include 'classes/' . $class . '.php';
}
spl_autoload_register('autoloader');
$math = new Math();
echo $math->add(2, 3);
开发者ID:nxnc,项目名称:WPF_MW,代码行数:9,代码来源:index.php

示例9: testAdd

 public function testAdd()
 {
     $math = new Math();
     $this->assertEquals(3, $math->add(1, 2));
     $this->assertEquals(10, $math->add(3, 7));
 }
开发者ID:atmarkcafe,项目名称:offshoredepart,代码行数:6,代码来源:MathTest.php

示例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);
开发者ID:bartolini69,项目名称:Laracast-Tutorials,代码行数:16,代码来源:Math.php


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