Quantcast

Important Math Functions in PHP

The importance of predefined mathematical functions for web programming as well as software design can not be overemphasized. PHP provides some very simple yet powerful math functions to undertake this task. The math functions in PHP can handle values within the range of integer and float types. Good thing is, the math functions are part of the PHP core. There is no installation needed to use these functions.

Some of the important math functions used in PHP are described below:

abs(): This functions returns the absolute value of a number. It takes a single variable as its parameter and returns it absolute value. For example:


The above code will return the absolute values of the three variables, which would be 6.7, 3 and 3.

ceil(x): This functions returns the value of a number rounded upwards to the nearest integer. For example:

The above code would return the ceiling values of the three variables which would be 1, 1 and 5.

Similarly, floor() function would return the value of a number rounded downwards to the nearest integer.

acos(): This functions returns the arccosine of a number. For example:

The above code would return the cosine values of the three variables which would be 0.876298061168, 1.57079632679 and 3.14159265359.

Similarly there are asin() and atan() functions which return the sin and tan values of its arguments.

exp(): This function returns the value of exponential value of its arguments. For example:

The above code would return the exp values of its arguments which would be 2.718281828459045 and 0.36787944117144233 respectively.

max(): This function would return the number with the highest value of two specified numbers. For example:

The above code would return 7, the maximum of the two numbers.

Similarly, there is min() function which return the minimum of the two numbers.

These and many other math functions are extensively utilized in PHP programming and serve to make the mathematical calculations very simple, precise and easy.

Looking for a quality hosting service? here are a few I suggest.
BlueHost | HostGator | Media Temple
Admin
Admin
Ali has been an entrepreneur in web, video and related technologies. Having worked with many business across the globe, Ali stands truly a great pillar in the business working with him.