PHP中常用的数学函数

PHP中常用的数学函数如下:

/**
 * 数学函数
 */
$abs =  abs(-3.3);  // return float|int The absolute value of number
$ceil = ceil(2.0001); // return float value rounded up to the next highest
$floor = floor(3.9);  // return float value rounded to the next lowest integer.
$fmod = fmod(3,2);    // return float The floating point remainder of
$pow = pow(2,3);  // return int|float base raised to the power of exp.
$round = round(4.5);    // return float The rounded value
$sqrt = sqrt(9);        // return float The square root of arg
$max = max(1,2,3,4,5,6,7);  // return mixed max returns the numerically highest of the parameter values, either within a arg array or two arguments.
$min = min(0.9,1,2,3,4,5,6,7); // return mixed min returns the numerically lowest of the parameter values.
$mt_rand = mt_rand(1000,9999);  // return int A random integer value between min (or 0)
$rand = rand(1000,9999);  // return int A pseudo random value between min (or 0) and max (or getrandmax, inclusive)
$pi = pi();  // return float The value of pi as float

echo 'abs:'.$abs,"\n",'ceil:'.$ceil,"\n".'floor:'.$floor,"\n".'fmod:'.$fmod,
    "\n".'pow:'.$pow,"\n".'round:'.$round,"\n".'sqrt:'.$sqrt,"\n".'max:'.$max,
    "\n".'min:'.$min, "\n".'mt_rand:'.$mt_rand."\n",'rand:'.$rand."\n".'pi:'.$pi;
// output
abs:3.3 ceil:3 floor:3 fmod:1 pow:8 round:5 sqrt:3 max:7 min:0.9 mt_rand:9186 rand:2872 pi:3.1415926535898
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. 定义 函数是一个被命名的,独立的代码段,它执行特定的任务,并可能给调用它的程序一份返回值。 PHP的模块化程...
    楠哥哥_0b86阅读 3,767评论 1 2
  • 总结了一些开发中常用的函数: usleep() //函数延迟代码执行若干微秒。 unpack() //函数从二进制...
    ADL2022阅读 3,301评论 0 3
  • PHP常用函数大全 usleep() 函数延迟代码执行若干微秒。 unpack() 函数从二进制字符串对数据进行解...
    上街买菜丶迷倒老太阅读 5,188评论 0 20
  • 在编程中我们总要进行一些数学运算以及数字处理,尤其是浮点数的运算和处理,这篇文章主要介绍C语言下的数学库。而其他语...
    欧阳大哥2013阅读 10,729评论 0 12
  • 目录### 一、函数的定义二、自定义函数三、函数的工作原理和结构化编程四、PHP变量的范围五、声明及应用各种形式的...
    akon2016阅读 4,214评论 1 1