In this PHP tutorial, you will learn all about the Math functions used in PHP
The math functions are the built-in PHP functions that are used for the various mathematical operations. As we all know PHP is a server-side scripting language as it needs to process various data and the PHP math function provides various support to process those mathematical operations.
PHP has various math functions for processing the data. The most used math functions are mentioned below.
abs(number);
echo abs(7) . "\n";
echo abs(-7) . "\n";
echo abs(-3.45) . "\n";
echo abs(9);
Output:
7 7 3.45 9
floor(number);
echo floor(0.45) . "\n";
echo floor(7.29) . "\n";
echo floor(6) . "\n";
echo floor(8.2) . "\n";
echo floor(-9.1) . "\n";
echo floor(-8.9);
Output:
7 7 3.45 9
ceil();
echo ciel(-5.9);
Output:
-5
pi();
echo pi();
Output:
3.1415926535898
sqrt(number);
echo sqrt(4). "\n";
echo sqrt(25). "\n";
echo sqrt(81). "\n";
Output:
2 5 9
pow(x,y);
echo pow(4, 5). "\n";
echo pow(1.5, 3). "\n";
echo pow(-2.5, 2);
Output:
1024 3.375 6.25
decbin(number);
echo decbin(4). "\n";
echo decbin(25). "\n";
echo decbin(89);
Output:
100 11001 1011001
bindec(number);
echo bindec(100). "\n";
echo bindec(11001). "\n";
echo bindec(1011001);
Output:
4 25 89
dechex (number);
echo dechex(4). "\n";
echo dechex(15). "\n";
echo dechex(19);
Output:
4 f 13
decoct(number);
echo decoct(4). "\n";
echo decoct(15). "\n";
echo decoct(19);
Output:
4 17 23
sin(number);
echo sin(4). "\n";
echo sin(15). "\n";
echo sin(19);
Output:
-0.75680249530793 0.65028784015712 0.14987720966295
cos(number);
echo cos(4). "\n";
echo cos(15). "\n";
echo cos(19);
Output:
-0.65364362086361 -0.75968791285882 0.98870461818667
tan(number);
echo tan(4). "\n";
echo tan(15). "\n";
echo tan(19);
Output:
1.1578212823496 -0.85599340090852 0.1515894706124
log(number, base(optional));
echo log(4). "\n";
echo log(0). "\n";
echo log(5, 2);
Output:
1.3862943611199 -INF 2.3219280948874
fmod(x,y);
echo fmod(18, 3). "\n";
echo fmod(12, 5). "\n";
echo fmod(5, 2);
Output:
0 2 1