PHP Math

PHP provides many predefined math constants and functions that can be used to perform mathematical operations.

PHP Math: abs() function

The abs() function returns absolute value of given number. It returns an integer value but if you pass floating point value, it returns a float value.

Syntax

Example

Output:

PHP Math: ceil() function

The ceil() function rounds fractions up.

Syntax

Example

Output:

PHP Math: floor() function

The floor() function rounds fractions down.

Syntax

Example

Output:

PHP Math: sqrt() function

The sqrt() function returns square root of given argument.

Syntax

Example

Output:

PHP Math: decbin() function

The decbin() function converts decimal number into binary. It returns binary number as a string.

Syntax

Example

Output:

PHP Math: dechex() function

The dechex() function converts decimal number into hexadecimal. It returns hexadecimal representation of given number as a string.

Syntax

Example

Output:

PHP Math: decoct() function

The decoct() function converts decimal number into octal. It returns octal representation of given number as a string.

Syntax

Example

Output:

PHP Math: base_convert() function

The base_convert() function allows you to convert any base number to any base number. For example, you can convert hexadecimal number to binary, hexadecimal to octal, binary to octal, octal to hexadecimal, binary to decimal etc.

Syntax

Example

Output:

PHP Math: bindec() function

The bindec() function converts binary number into decimal.

Syntax

Example

Output:

PHP Math Functions

Let’s see the list of important PHP math functions.

  • abs()
  • acos()
  • acosh()
  • asin()
  • asinh()
  • atan()
  • atan2()
  • atanh()
  • base_convert()
  • bindec()
  • ceil()
  • cos()
  • cosh()
  • decbin()
  • dechex()
  • decoct()
  • deg2rad()
  • exp()
  • expm1()
  • floor()
  • fmod()
  • getrandmax()
  • hexdec()
  • hypot()
  • is_finite()
  • is_infinite()
  • is_nan()
  • lcg_value()
  • log()
  • log10()
  • log1p()
  • max()
  • min()
  • mt_getrandmax()
  • mt_rand()
  • mt_srand()
  • octdec()
  • pi()
  • pow()
  • rad2deg()
  • rand()
  • round()
  • sin()
  • sinh()
  • sqrt()
  • srand()
  • tan()
  • tanh()
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *