PHP Math Functions - pi, abs, sqrt, min, max, rand, round, floor, ceil, pow, is_nan, is_numeric
Categories - PHP Tags - PHP   Maniruzzaman Akash   1 week ago   57   0

PHP Math Functions - pi, abs, sqrt, min, max, rand, round, floor, ceil, pow, is_nan, is_numeric

PHP Math Function

PHP has several built in methods to work with Mathematics. Let’s get the list of that -

Method Name Description Example Result
pi() Get Pi number value echo pi(); // 3.1415926535898 Return PI value
abs() Get the absolute value of a variable or operand echo abs(-1); // 1 Return Positive value of integer
min(val1, val2) Get the minimum value of two or multiple variable or multiple operand echo min(10, 20); // 10 Return minimum value
max(val1, val2) Get the maximum value of two or multiple variable or multiple operand echo max(10, 20); // 20 Return maximum value
sqrt(val) Get the square root of a variable or operand echo sqrt(64); // 8 Return square root value
rand() or rand(min, max) Get a random integer echo rand(5, 10); // 8 Return random integer value between those range.
round(floatvalue) Get a rounded value echo round(3.4); // 3
echo round(3.5); // 4
Return round value of any float number.
floor(floatvalue) Get a lowest integer value echo floor(3.6); // 3 Return lowest value of any float number.
ceil(floatvalue) Get a highest integer value echo ceil(3.1); // 4 Return highest value of any float number.
pow(num, exponent) Get a power of a number echo pow(5, 2); // 25 Return power value of a number.
is_nan(num) Check if the value of is not number. echo is_nan("test"); // true Return true if the num is Not a Number.
is_numeric(num) Check if the value of is a number. echo is_numeric("test"); // false Return true if the num is a valid Number.
Previous
PHP If-else-elseif and Switch-case
Next
PHP String Functions - All necessary String functions in PHP to manage strings better.