PHP Math
PHP offers a collection of math features to execute number-related math operations.
PHP pi() Function
The PI value is returned by the pi()
function.
Example :-
Output :-
PHP min() and max() Functions
In a list of inputs, the min()
and max()
methods can be
used to get the lowest and highest number.
Example :-
Output :-
150
PHP abs() Function
The absolute (positive) value of an integer is returned by the abs()
function.
Example :-
";
echo(abs(-3.1)); // returns 3.1
echo "
";
echo(abs(2)); // returns 2
?>
Output :-
3.1
2
Related Links
PHP sqrt() Function
The square root of an integer is returned by the sqrt()
function.
Example :-
";
echo(sqrt(9)); // returns 3
?>
Output :-
3
PHP round() Function
floating-point value is rounded to the nearest integer using the round()
function.
Example :-
Output :-
0
Related Links
Random Numbers
The rand()
function is used to generate or create an random integer number.
Example 1 :-
";
echo(rand());
?>
Output :-
1000111223
Note :- It will generate any number between minimum and maximum of an integer value.
Example 2 :- If you want a random integer between 10 and 100 (inclusive), use rand(10, 100):
";
echo(rand(10, 100));
?>
Output :-
32
Complete PHP Math Reference
For a complete reference of all math functions, go to our complete PHP Math Reference.
The PHP math reference contains description and example of use, for each function.