1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

PHP Math Functions


Operators and Operands:

Math expressions in PHP are made up of operators and operands. Basic math like adding, subtracting, multiplying and dividing can be done using mathematical operators. We also use comparison operators in equations to represent greater than (>) less than (<) and equal to (=).

Rounding Numbers:

There are several ways to round a number in PHP. One way is to simply round the number in the traditional way (anything .5 or over goes up, under goes down.) You can also use ceil to round all numbers up, or use floor to round all numbers down.


One commonly used constant in geometry is pi (?). There are several ways to use pi and variations of pi in PHP. Some other useful geometry PHP functions are sine, cosine, and tangent.

Roots and Exponents:

You can raise a number to any power in PHP using the pow () function. Similarly you can find its root. To find the square root you would use sqrt ().

Absolute Value:

The absolute value of a number, is the distance a number is from 0, and is always a positive number. The absolute value function in PHP produces this for us.

Formatting Numbers:

Numbers are formatted differently in different parts of the world. In the US, it is common to format using commas and periods such as: 1,000,000.00 In PHP we can set our numbers to format however we want, to make them the most useful for us.

Max and Min Functions:

The max () and min () functions can be used to find the highest or lowest number in a group of numbers, arrays, and strings. The max () function is used to find the highest, and the min () function is used to find the lowest.
Related Video
Basic PHP Syntax
Using PHP With HTML
  1. About.com
  2. Technology
  3. PHP / MySQL
  4. Learn PHP
  5. PHP Math Functions - PHP Mathematics - Math Functions PHP

©2014 About.com. All rights reserved.