php数学函数
integer(整型)
integer 为整数型别。在 32 位的操作系统中,它的有效范围是 -2,147,483,648 到 +2,147,483,647 (2^31+符号位)。要使用 16 进位整数可以在面加 0x。 整型值可以用十进制,十六进制或八进制符号指定,前面可以加上可选的符号(- 或者 +)。
十进制:如果看到15时,它表示(1*10+5)或1510
包含(0...9)十个数字
八进制:如果看到15时,它表示(1*8+5)或158 或 1310
包含(0...7)八个数字
十六进制:如果看到15时,它表示(1*16+5)或1516 或 2110
包含(0...9,A,B,C,D,E,F)十六个数字
如果用八进制符号,数字前必须加上 0(零),用十六进制符号数字前必须加上 0x。
$a = 1234; // 十进制数
$a = -123; // 一个负数
$a = 0123; // 八进制数(等于十进制的 83)
$a = 0x1A; // 十六进制数(等于十进制的 26)
?>
浮点数为浮点数型别。在 32 位的操作系统中,它的有效范围是 1.7E-308 到 1.7E+308。(自然底数e=2.71828183)
$a = 1.234;
$a = 1.2e3;
$a = 7E-10;
?>
$foo = 10; // $foo is an integer |
允许的强制转换有:
(int),(integer) - 转换成整型 无四舍五入 (bool),(boolean) - 转换成布尔型 不为0的正数或负数都为true (float),(double),(real) - 转换成浮点型 (string) - 转换成字符串数学运算函数库
Abs
取得绝对值。
语法: mixed abs(mixed number);
返回值: 混合类型资料
函数种类: 数学运算
内容说明 |
返回参数 number 的绝对值。若 number 是倍精确浮点数,则返回值也是倍浮点数;其它的类型则返回类型为整数。
Acos
取得反余弦值。
语法: float acos(float arg);
返回值: 浮点数
函数种类: 数学运算
内容说明 |
返回参数 arg 的反余弦值 (arc cosine)。
Asin
取得反正弦值。
语法: float asin(float arg);
返回值: 浮点数
函数种类: 数学运算
内容说明 |
返回参数 arg 的反正弦值 (arc sine)。
Atan
取得反正切值。
语法: float atan(float arg);
返回值: 浮点数
函数种类: 数学运算
内容说明 |
返回参数 arg 的反正切值 (arc tangent)。
Atan2
计算二数的反正切值。 语法: float atan2(float y, float x); 返回值: 浮点数 函数种类: 数学运算
内容说明 |
本函数用来计算二数 y、x 的反正切值,计算结果与 atan() 计算 y/x 类似,但本函数会因 x、y 的正负号影响结果。而本函数的返回值必落在正负的圆周率间 (-PI
BinDec
二进位转成十进位。
语法: int bindec(string binary_string);
返回值: 整数
函数种类: 数学运算
内容说明 |
本函数将二进位数字字符串转成十进位的整数。由于 PHP 使用 32 位有正负号整数计算,能处理的最大十进位数字为 2147483647,也就是二进位数字的 1111111111111111111111111111111 (31 个 1)。
Ceil
计算大于指定数的最小整数。
语法: int ceil(float number);
返回值: 整数
函数种类: 数学运算
内容说明 |
本函数用来计算比浮点参数 number 大的最小整数。
使用范例 |
本例返回值为 4。
$nextint=ceil(3.14);
echo $nextint;
?>
Cos
余弦计算。
语法: float cos(float arg);
返回值: 浮点数
函数种类: 数学运算
内容说明 |
本函数计算参数 arg 的余弦值 (cosine)。
DecBin
十进位转二进位。
语法: string decbin(int number);
返回值: 字符串
函数种类: 数学运算
内容说明 |
本函数将十进位数字转成二进位字符串。由于 PHP 使用 32 位有正负号整数计算,能处理的最大十进位数字为 2147483647,也就是二进位数字的 1111111111111111111111111111111 (31 个 1)。
Exp
自然对数 e 的次方值。
语法: float exp(float arg);
返回值: 浮点数
函数种类: 数学运算
内容说明 |
本函数计算自然对数 (natural logarithm) 的 arg 次方值。
Floor
计算小于指定数的最大整数。
语法: int floor(float number);
返回值: 整数
函数种类: 数学运算
内容说明 |
本函数用来计算比浮点参数 number 小的最大整数。
使用范例 |
本例返回值为 3。
$lastint=floor(3.14);
echo $lastint;
?>
max
取得最大值。
语法: mixed max(mixed arg1, mixed arg2 .... mixed argn);
返回值: 混合类型资料
函数种类: 数学运算
内容说明 |
本函数计算参数间的最大值。若第一个参数是数字数组,则会找出该数组的最大数字。若第一个参数非数组,则需二个以上的参 数。这些数字可以是整数、倍精确数或数字字符串的类型。参数的数目不限,视用户的需求而定。在计算时,只要有一个参数是倍精确数,本函数会将所有的参数都 转成倍精确数,并返回倍精确数。若参数只有整数及数字字符串,则会将所有的参数转换成整数,并返回整数。
min
取得最小值。
语法: mixed min(mixed arg1, mixed arg2 .... mixed argn);
返回值: 混合类型资料
函数种类: 数学运算
内容说明 |
本函数计算参数间的最小值。若第一个参数是数字数组,则会找出该数组的最小数字。若第一个参数非数组,则需二个以上的参 数。这些数字可以是整数、倍精确数或数字字符串的类型。参数的数目不限,视用户的需求而定。在计算时,只要有一个参数是倍精确数,本函数会将所有的参数都 转成倍精确数,并返回倍精确数。若参数只有整数及数字字符串,则会将所有的参数转换成整数,并返回整数。
number_format
格式化数字字符串。
语法: string number_format(float number, int [decimals], string [dec_point], string [thousands_sep]);
返回值: 字符串
函数种类: 数学运算
内容说明 |
本函数用来将浮点参数 number 格式化。若没加参数 decimals 则返回的字符串只要整数部份,加了此参数才依参数指定的小数点位数返回。参数 dec_point 表示小数点的表示方式方法,默认值是 ".",若需要转换成其它的小数点就可以在这个参数改掉。参数 thousands_sep 为整数部份每三位的分隔符号,默认值是 ","。本函数最特别的地方就是参数数目,最少要有一个,也就是欲格式化的字符串;也可以有二个或者四个参数,但不能用三个参数。治募?注意的是指定小数 点的位数之后的数字直接舍弃,没有四舍五入的情形。
使用范例 |
$short_pi = "3.14159";
$my_pi = number_format($short_pi, 2);
echo $my_pi."\n"; // 3.14
$foo = 850017.9021;
$new_foo = number_format($foo, 3, ".", " ");
echo $new_foo."\n"; // 850 017.902
?>
pi
圆周率。
语法: double pi(void);
返回值: 倍精确数
函数种类: 数学运算
内容说明 |
本函数返回圆周率。不需输入参数。
pow
次方。
语法: float pow(float base, float exp);
返回值: 浮点数
函数种类: 数学运算
内容说明 |
本函数计算次方值。参数 base 为基底,exp 为幂数。
使用范例 |
print(pow(2,3)); // 8
print(pow(5,4)); // 625
?>
rand
取得随机数值。
语法: int rand([int min], [int max]);
返回值: 整数
函数种类: 数学运算
内容说明 |
本函数用来取得随机数值。若没有指定随机数的最大及最小范围,本函数会自动的从 0 到 RAND_MAX 中取一个随机数。若有指定 min 及 max 的参数,则从指定参数中取一个数字。例如 rand(38, 49) 则会从 38 到 49 之间取一个随机数值,UNIX 系统包含 49、Win32 系统不包含 49 (zkimmel@earthlink.net 10-May-1999)。值得注意的是为使随机数的乱度最大,每次在取随机数之前最好使用 srand() 以配置新的随机数种子。
round
四舍五入。
语法: double round(double val);
返回值: 倍精确数
函数种类: 数学运算
内容说明 |
本函数用来将数字小数点后四舍五入。
使用范例 |
$foo1 = round(3.4);
$foo2 = round(3.5);
$foo3 = round(3.6);
echo "round(3.4): ".$foo1."
\n";
echo "round(3.5): ".$foo2."
\n";
echo "round(3.6): ".$foo3;
?>
Sin
正弦计算。
语法: float sin(float arg);
返回值: 浮点数
函数种类: 数学运算
内容说明 |
本函数计算参数 arg 的正弦值 (sine)。
Sqrt
开平方根。
语法: float sqrt(float arg);
返回值: 浮点数
函数种类: 数学运算
内容说明 |
本函数将参数 arg 开平方根。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.
