Source: Internet
Author: User

PHP Math function Summary (classic worth collecting), PHP is worth collecting

This paper summarizes and analyzes the mathematical operation function of PHP. Share to everyone for your reference, as follows:

**First, the common function description:**

Abs: Get absolute value.

Acos: Gets the inverse cosine value.

Asin: Gets the inverse sine value.

Atan: Gets the inverse tangent value.

Atan2: Calculates the inverse tangent of two numbers.

Base_convert: Converts the carry mode of a number.

Bindec: binary turns into 10 decimal.

Ceil: Calculates the smallest integer greater than the specified number.

COS: cosine calculation.

Decbin: the decimal binary.

Dechex: Decimal Turn 16.

DECOCT: Decimal turn octal.

EXP: The secondary value of the natural logarithm E.

Floor: Calculates the largest integer less than the specified number.

Getrandmax: The maximum value of the random number.

Hexdec: 16 Carry round decimal.

Log: Natural pairs of values.

The value of the Log10:10 base.

Max: Gets the maximum value.

Min: Gets the minimum value.

Mt_rand: Gets a random value.

Mt_srand: Configures random number seed.

Mt_getrandmax: The maximum value of the random number.

Number_format: Formats a numeric string.

Octdec: Octal turn decimal.

Pi: Pi.

POW: the second party.

Rand: Get a random number.

Round: Rounding.

Sin: sine calculation.

Sqrt: Open square root.

Srand: Configures random number seed.

Tan: Tangent calculation.

**Second, the function analysis is as follows:**

Abs

Get the absolute value.

Syntax: Mixed ABS (mixed number);

Return value: Mixed type data

Types of functions: mathematical operations

Content Description: Returns the absolute value of the parameter number. If number is a multiple-precision floating-point, the return value is also a double-floating point, and the other type is an integer.

Acos

Gets the inverse cosine value.

Syntax: float acos (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Content Description: Returns the inverse cosine value of the parameter arg (ARC cosine).

Reference: ASIN () Atan ()

Asin

Get the inverse sine value.

Syntax: Float ASIN (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Description: Returns the inverse sine value of the parameter arg (arc sine).

Reference: ACOs () Atan ()

Atan

Gets the inverse tangent value.

Syntax: float atan (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Description: Returns the inverse tangent value of the parameter arg (arc tangent).

Reference: ACOs () ASIN ()

Atan2

Calculates the inverse tangent of two numbers.

Syntax: float atan2 (float y, float x);

return value: Floating-point number

Types of functions: mathematical operations

Description: This function is used to calculate the inverse tangent value of two number Y, x, and the calculated result is similar to Atan () calculation y/x, but this function will affect the result by the sign of X and Y. And the return value of this function must fall between positive and negative pi (-pi <= (value) ≶= pi)

Reference ACOs () Atan () ASIN ()

Base_convert

Converts the carry mode of a number.

Syntax: string Base_convert (string number, int frombase, int tobase);

return value: String

Types of functions: mathematical operations

Description: This function converts the numeric string number from Frombase to tobase rounding. This can be handled by a binary to a 36-in-a-carry mode. Before the decimal, it is expressed as a number, and it is expressed in English letters after the decimal. For example, a 16-digit single-digit sequence of 123456789abcdef,10 is the 17th, when only one is entered. While 36 A is tenth, B is 11th, Z is 36th, and 10 is 37th, then carry.

Usage examples

This example turns a 16-digit string into a binary string

<?php$binary = Base_convert ($hexadecimal, 2); echo "16 string" $hexadecimal "goes binary to" $binary ". ";? >

Bindec

Binary turns into 10.

Syntax: int bindec (string binary_string);

return value: Integer

Types of functions: mathematical operations

Description: This function converts a binary numeric string into an integer of 10. Since PHP uses a 32-bit signed integer, the maximum number of decimal digits that can be processed is 2147483647, which is 1111111111111111111111111111111 (31 1) of the binary number.

Reference: Decbin ()

Ceil

Calculates the smallest integer greater than the specified number.

Syntax: int ceil (float number);

return value: Integer

Types of functions: mathematical operations

Description: This function is used to calculate the smallest integer larger than the floating-point parameter number.

Usage examples

This example returns a value of 4.

Reference: Floor () round ()

Cos

Cosine calculation.

Syntax: float cos (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Description: This function calculates the cosine value of the parameter arg (cosine).

Reference: Sin () Tan ()

Decbin

Decimal round binary.

Syntax: string decbin (int number);

return value: String

Types of functions: mathematical operations

Description: This function turns the decimal number into a binary string. Since PHP uses a 32-bit signed integer, the maximum number of decimal digits that can be processed is 2147483647, which is 1111111111111111111111111111111 (31 1) of the binary number.

Reference: Bindec ()

Dechex

Decimal Turn 16.

Syntax: string dechex (int number);

return value: String

Types of functions: mathematical operations

Description: This function turns the decimal number into a 16-digit string. Since PHP uses a 32-bit signed integer, the maximum number of decimal digits that can be processed is 2147483647, which is the 16-digit 7fffffff.

Reference: Hexdec ()

Decoct

Decimal turn octal.

Syntax: string decoct (int number);

return value: String

Types of functions: mathematical operations

Description: This function turns the decimal number into an octal string. Since PHP uses a 32-bit signed integer, the maximum number of decimal digits that can be processed is 2147483647, which is the octal number 17777777777.

Reference: Octdec ()

Exp

The secondary value of the natural logarithm E.

Syntax: float exp (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Description: This function calculates the arg value of the natural logarithm (natural logarithm).

Reference: POW () Log ()

Floor

Calculates the largest integer less than the specified number.

Syntax: int floor (float number);

return value: Integer

Types of functions: mathematical operations

Description: This function is used to calculate the largest integer smaller than the floating-point parameter number.

Usage examples

This example returns a value of 3.

Reference: Ceil () round ()

Getrandmax

The maximum value of the random number.

Syntax: int getrandmax (void);

return value: Integer

Types of functions: mathematical operations

Description: This function calculates the maximum number of chaotic values that can be obtained by the Random function rand (). This function does not require parameters.

Reference: Rand () Srand () Mt_rand () Mt_srand () Mt_getrandmax ()

Hexdec

16 Carry round decimal.

Syntax: int hexdec (string hex_string);

return value: Integer

Types of functions: mathematical operations

Description: This function converts a 16-digit string into a 10-decimal number. Since PHP uses a 32-bit signed integer, the maximum number of 16 digits that can be processed is 7FFFFFFF, which is 2147483647 of the decimal number.

Reference: Dechex ()

Log

Natural pairs of values.

Syntax: float log (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Description: This function calculates the natural logarithm (natural logarithm) value of the parameter arg.

Log10

10 The pair value of the substrate.

Syntax: float log10 (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Description: This function calculates the 10 base pair value of the parameter arg.

Max

Gets the maximum value.

Syntax: Mixed max (mixed arg1, mixed arg2 .... mixed argn);

Return value: Mixed type data

Types of functions: mathematical operations

Description: This function calculates the maximum value between parameters. If the first argument is a numeric array, the maximum number of the array is found. If the first parameter is not an array, then more than two parameters are required. These numbers can be integers, multiples of exact numbers, or types of numeric strings. The number of parameters is not limited, depending on the needs of users. In the calculation, as long as one parameter is the exact number of times, this function will turn all the parameters into multiples of the exact number and return the exact number of times. If the argument has only integers and numeric strings, all arguments are converted to integers and integers are returned.

Reference: Min ()

Min

Gets the minimum value.

Syntax: mixed min (mixed arg1, mixed arg2 .... mixed argn);

Return value: Mixed type data

Types of functions: mathematical operations

Description: This function calculates the minimum value between parameters. If the first argument is a numeric array, the smallest number of the array is found. If the first parameter is not an array, then more than two parameters are required. These numbers can be integers, multiples of exact numbers, or types of numeric strings. The number of parameters is not limited, depending on the needs of users. In the calculation, as long as one parameter is the exact number of times, this function will turn all the parameters into multiples of the exact number and return the exact number of times. If the argument has only integers and numeric strings, all arguments are converted to integers and integers are returned.

Reference: Max ()

Mt_rand

Get random values.

Syntax: int mt_rand ([int min], [int Max]);

return value: Integer

Types of functions: mathematical operations

Description: This function does not use commonly used libc to calculate chaotic values, but uses the horse's Dorset rotation (Mersenne Twister) algorithm to calculate the chaotic values at least four times times faster. For more information on the http://www.math.keio.ac.jp/~matumoto/emt.html, the best original program is found in the Http://www.scp.syr.edu/~marc, which is the new method of the Matterhorn rotation algorithm. /hawk/twister.html. Without specifying the maximum and minimum range of chaos, this function automatically takes a random number from 0 to Rand_max. If a parameter of min and Max is specified, a number is taken from the specified argument, such as Mt_rand (38, 49), which takes a random value from 38 to 49. It is worth noting that in order to make the disorder of chaos Maximum, it is best to use Mt_srand () to configure a new random number seed each time before the scrambling number.

Reference: Rand () Srand () Getrandmax () Mt_srand () Mt_getrandmax ()

Mt_srand

Configure the seed for the random number.

Syntax: void mt_srand (int seed);

return value: None

Types of functions: mathematical operations

Description: After this function passes in the parameter seed, configures the seed of the random number. It is important to note that the parameter seed value is best also a random number, such as the use of time as the source of the variable is a good way, or the development of other hardware peripheral interface can achieve better chaos.

Usage examples

This example adds time to the factor to execute when the seed is one out of 10,000 seconds when the random number

Reference: Rand () Srand () Getrandmax () Mt_rand () Mt_getrandmax ()

Mt_getrandmax

The maximum value of the random number.

Syntax: int mt_getrandmax (void);

return value: Integer

Types of functions: mathematical operations

Description: This function calculates the maximum number of chaotic values that can be obtained from the Mt_rand () function. This function does not require parameters.

Reference: Rand () Srand () Getrandmax () Mt_srand () Mt_rand ()

Number_format

Formats a numeric string.

Syntax: string Number_format (float number, int [decimals], string [Dec_point], string [thousands_sep]);

return value: String

Types of functions: mathematical operations

Description: This function is used to format the floating-point parameter number. If the parameter is not decimals the returned string is returned as long as the integer part is added to the number of decimal places specified by the parameter. The parameter dec_point represents the method of how the decimal point is represented, and the default value is ".", which can be broken in this parameter if it needs to be converted to another decimal point. The parameter thousands_sep is a three-bit separator for integral parts, and the default value is ",". The most special place of this function is the number of parameters, at least one, that is, to format the string, you can have two or four parameters, but not three parameters. It is noteworthy that the number of digits after the specified decimal point is discarded directly, without rounding the case.

Usage examples

<?PHP$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?>

Octdec

Octal turn decimal.

Syntax: string decoct (int number);

return value: String

Types of functions: mathematical operations

Description: This function turns the octal string into a 10-digit number. Since PHP uses a 32-bit signed integer, it can handle the maximum octal number as 17777777777, which is the decimal number of 2147483647.

Reference: Decoct ()

Pi

Pi.

Syntax: Double pi (void);

Return value: The exact number of times

Types of functions: mathematical operations

Content Description: This function returns PI. No input parameters are required.

Pow

The second party.

Syntax: Float POW (float base, float exp);

return value: Floating-point number

Types of functions: mathematical operations

Description: This function calculates the sub-square value. The parameter base is the base and exp is the power number.

Usage examples

Reference: Log10 () Exp ()

Rand

Obtain a random value.

Syntax: int rand ([int min], [int Max]);

return value: Integer

Types of functions: mathematical operations

Description: This function is used to obtain a random value. Without specifying the maximum and minimum range of random numbers, this function automatically takes a random number from 0 to Rand_max. If a parameter of min and Max is specified, a number is taken from the specified parameter. For example, Rand (38, 49) takes a random value from 38 to 49, and the UNIX system contains 49, and the WIN32 system does not contain a ([Email=zkimmel@earthlink.net]zkimmel@earthlink.net[/ema IL] 10-may-1999). It is important to note that in order to make the random number the most chaotic, it is best to use Srand () to configure a new random number seed each time before taking the random number.

Reference: Srand () Getrandmax () Mt_rand () Mt_srand () Mt_getrandmax ()

Round

Rounded.

Syntax: Double round (double val);

Return value: The exact number of times

Types of functions: mathematical operations

Description: This function is used to round the digits after the decimal point.

Usage examples

<?php$foo1 = Round (3.4), $foo 2 = round (3.5), $foo 3 = round (3.6), echo "Round (3.4):". $foo 1. "

n "; Echo" round (3.5): ". $foo 2."

n "; Echo" Round (3.6): ". $foo 3;? >

Reference: Ceil () floor ()

Sin

Sine calculation.

Syntax: float sin (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Description: This function calculates the sine value of the parameter arg (sine).

Reference: Cos () Tan ()

Sqrt

Open square root.

Syntax: float sqrt (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Description: This function will open the square root of the parameter arg.

Srand

Configures a random number seed.

Syntax: void srand (int seed);

return value: None

Types of functions: mathematical operations

Description: After the function passes in the parameter seed, the seed of the random number is configured. It is important to note that the parameter seed value is best also a random number, such as the use of time as the source of the variable is a good way, or the development of other hardware peripheral interface to obtain a better random number.

Usage examples

This example adds time to the factor to execute when the random number seed is one out of 10,000 seconds

Reference: Rand () Getrandmax () Mt_srand () Mt_rand () Mt_getrandmax ()

Tan

Tangent calculation.

Syntax: float tan (float arg);

return value: Floating-point number

Types of functions: mathematical operations

Description: This function calculates the tangent value of the parameter arg (tangent).

Reference: Sin () Cos ()

More readers interested in PHP related content can view this site: "Summary of PHP operations and operator usage," PHP Network Programming Tips Summary, "PHP Basic Grammar Primer Tutorial", "PHP operation Office Document tips summary (including word,excel,access, ppt), "PHP Date and Time usage summary", "PHP primer for Object-oriented programming", "PHP String Usage Summary", "Getting Started with Php+mysql database operations" and "PHP Common Database Operations Skills Summary"

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

- PHP Array function array_multisort () Usage Example analysis
- PHP computes the sum and product of values in an array (Array_sum and array_product functions)
- An explanation of PHP anonymous functions and precautions
- Summary of common array function usage in PHP
- PHP anonymous function and use clause usage instance
- Simply talk about the strlen function in PHP
- Analysis of source code of Array_keys and Array_unique functions in PHP
- Php method for querying and deleting multiple columns of data in a database (using array functions)
- PHP Powerful Time-conversion function strtotime
- PHP function Timeout processing method
- Probe into the anonymous function of PHP's closure (Closure)
- php function Import_request_variables () usage analysis

http://www.bkjia.com/PHPjc/1117049.html www.bkjia.com true http://www.bkjia.com/PHPjc/1117049.html techarticle PHP Math Function Summary (classic is worth collecting), PHP is worth collecting this article summarizes and analyzes the mathematical functions of PHP. Share to everyone for reference, as follows: One, commonly used function said ...

Related Article