➤ In this note we will look at some commonly used math functions. •
pi()
// pi() function returns the value of PI:
echo pi(); // outputs 3.1415926535898
min()
max()
// min() and max() functions can be used to find the lowest or highest value in a list of arguments:
echo (min(1, 4, 35, -9, 48));  // outputs -9
echo (max(41, 12, 89, 23, -19));  // outputs 89
abs()
// abs() function returns the absolute (positive) value of a number:
echo abs(-4.5);  // outputs 4.5
sqrt()
// sqrt() function returns the square root of a number:
echo sqrt(81);  // outputs 9
round()
// round() function rounds a floating-point number to its nearest integer:
echo round(1.7); // outputs 2
echo round(1.3); // outputs 1
floor()
// floor() function rounds a number DOWN to the nearest integer:
echo floor(2.4); // outputs 2 
echo floor(3.8); // outputs 3 
echo floor(-1.1); // outputs -2
rand()
// rand() function generates a random number:
echo rand();
// Alo we can add the optional min and max parameters to specify the lowest integer 
// and the highest integer to be returned.
// For instance, random integer between 1 and 10 (inclusive), use rand(10, 100):
echo rand(1, 10);
count()
// count() function returns the number of elements in an array:
$countries = array("Georgia","Ukraine","Spain");
echo count($countries); // outputs 3
pow()
// pow() function returns x raised to the power of y. ( x = 2 , y = 3):
echo pow(2,3); // outputs 8
decbin()
// decbin() function converts decimal to binary:
echo decbin(2);// outputs 10
echo "\n";
echo decbin(10); // outputs 1010
by Levani Makhareishvili
2 years ago
PHP
Function
1
Pro tip: use ```triple backticks around text``` to write in code fences