Mathematical Functions in PHP
Math Functions is used to hold the integer and float value within a certain range.
1. abs :-
It is used to give the result in a positive number of distinct numbers.
<?php
echo(abs(90.7) . "<br>");
echo(abs(-78.744) . "<br>");
echo(abs(-300) . "<br>");
echo(abs(3));
?>
Output
90.7
78.744
300
3
2. acos :-
It is used to return the value in the arc cosine of distinct number.
<?php
echo(acos(0.28) . "<br>");
echo(acos(-0.67) . "<br>");
echo(acos(01) . "<br>");
echo(acos(-1) . "<br>");
echo(acos(1) . "<br>");
echo(acos(2));
?>
Output
1.2870022175866
2.3050051142483
0
3.1415926535898
0
NAN
3. asin :-
It is used to return the value in the arc sine of distinct number.
<?php
echo(asin(0.28) . "<br>");
echo(asin(-0.67) . "<br>");
echo(asin(01) . "<br>");
echo(asin(-1) . "<br>");
echo(asin(1) . "<br>");
echo(asin(2));
?>
.Output
0.69449826562656
-0.41151684606749
0
-1.5707963267949
1.5707963267949
NAN
4. asinh :-
It is used to return the reverse hyperbolic sine of distinct number.
<?php
echo(asinh(0.28) . "<br>");
echo(asinh(126) . "<br>");
echo(asinh(02.45));
?>
Output
2.6441207610586
4.7185785811518
1.6284998192842
5. atan2 :-
It is used to return the arc tangent of two variable.
<?php
echo(atan2(10.250,0.550) . "<br>");
echo(atan2(-0.-5,-0.15) . "<br>");
echo(atan2(2,5) . "<br>");
echo(atan2(11,12) . "<br>");
echo(atan2(-4,-3) . "<br>");
echo(atan2(10,-40));
?>
Output
0.78539816339745
-2.3561944901923
0.78539816339745
0.46364760900081
-2.3561944901923
-0.78539816339745
6.atan :-
It is used to return the arc tangent of distinct number.
<?php
echo(atan(210.150) . "<br>");
echo(atan(-20.10) . "<br>");
echo(atan(15) . "<br>");
echo(atan(-51) . "<br>");
echo(atan(-10) . "<br>");
echo(atan(-102));
?>
Output
1.5660378568815
-1.5210860700257
1.5042281630191
-1.5511909959377
-1.4711276743037
-1.5609927193156
7. atanh :-
It is used to return the reverse hyperbolic tangent of distinct number.
<?php
echo(atanh(M_PI_4) . "<br>");
echo(atanh(0.120) . "<br>");
echo(atanh(-0.174) . "<br>");
echo(atanh(11) . "<br>");
echo(atanh(-1));
?>
Output
1.0593061708232
0.12058102840844
-0.17578861343353
NAN
-INF
8. base_convert :-
It changes the hexadecimal number into octal number.
<?php
$hex = "E136";
echo base_convert($hex,12,6);
?>
Output
510
9. bindec :-
It is used to convert the binary number into decimal.
<?php
echo bindec("0110") . "<br>";
echo bindec("0100011") . "<br>";
echo bindec("110011110011") . "<br>";
echo bindec("1110");
?>
Output
6
35
3315
14
10.ceil :-
It is used to round the number into the nearest integer number.
<?php
echo(ceil(0.160) . "<br>");
echo(ceil(0.47) . "<br>");
echo(ceil(58) . "<br>");
echo(ceil(25.1) . "<br>");
echo(ceil(-15.10) . "<br>");
echo(ceil(-5.90));
?>
Output
1
1
58
26
-15
-5
11. cos :-
It is used to return the cosine of distinct number.
<?php
echo(cos(30) . "<br>");
echo(cos(-45) . "<br>");
echo(cos(10) . "<br>");
echo(cos(M_PI) . "<br>");
echo(cos(4*M_PI));
?>
Output
0.15425144988758
0.52532198881773
-0.83907152907645
-1
1
12. decbin :-
It is used to convert the decimal number into binary.
<?php
echo decbin("9") . "<br>";
echo decbin("21") . "<br>";
echo decbin("1027") . "<br>";
echo decbin("-1789") . "<br>";
echo decbin("17");
?>
Output
1001
10101
10000000011
1111111111111111111111111111111111111111111111111111100100000011
10001
13. dechex :-
It is used to convert the decimal number into hexadecimal.
<?php
echo dechex("9") . "<br>";
echo dechex("21") . "<br>";
echo dechex("1027") . "<br>";
echo dechex("-1789") . "<br>";
echo dechex("17");
?>
Output
9
15
403
fffffffffffff903
11.
14. decoct :-
It is used to convert the decimal number into octal.
<?php
echo decoct("9") . "<br>";
echo decoct("21") . "<br>";
echo decoct("1027") . "<br>";
echo decoct("-1789") . "<br>";
echo decoct("17");
?>
Output
11
25
2003
1777777777777777774403
21
15. deg2rad :-
It is used to convert the degree into radians.
<?php
echo deg2rad("25") . "<br>";
echo deg2rad("35") . "<br>";
echo deg2rad("40") . "<br>";
echo deg2rad("75") . "<br>";
echo deg2rad("180") . "<br>";
echo deg2rad("360");
?>
Output
0.43633231299858
0.61086523819802
0.69813170079773
1.3089969389957
3.1415926535898
6.2831853071796
16. exp :-
It is used to calculate the exponent of 'e'.
<?php
echo(exp(10) . "<br>");
echo(exp(1) . "<br>");
echo(exp(-9) . "<br>");
echo(exp(20) . "<br>");
echo(exp(34.08));
?>
Output
22026.465794807
2.718281828459
0.00012340980408668
485165195.40979
6.3205656016309E+14
17. expm1 :-
It returns the exp() -1 and calculated a correct even when the number is close to zero.
<?php
echo(expm1(0) . "<br>");
echo(expm1(11) . "<br>");
echo(expm1(101) . "<br>");
echo(expm1(14.80));
?>
Output
0
59873.141715198
7.3070599793681E+43
2676444.0551891
18. floor :-
It is used to round the number into descending in the closest integer.
<?php
echo(floor(10.60) . "<br>");
echo(floor(0.98) . "<br>");
echo(floor(45) . "<br>");
echo(floor(25.1) . "<br>");
echo(floor(-75.1) . "<br>");
echo(floor(-52.9));
?>
Output
10
0
45
25
-76
-53
19. fmod :-
It is used to return the remainder of the division.
<?php
$x = 150;
$y = 380;
$result = fmod($x,$y);
echo $result;
?>
Output
150
20. getrandmax :-
It is used to return the largest random value.
<?php
echo(getrandmax());
?>
Output
2147483647
21. hexdec :-
It is used to convert the hexadecimal number into decimal.
<?php
echo hexdec("12e") . "<br>";
echo hexdec("2a") . "<br>";
echo hexdec("189cf") . "<br>";
echo hexdec("ccee1f");
?>
Output
302
42
100815
13430303
22. hypot:-
It is used to calculate the hypotenuse of different right angle triangles.
<?php
echo hypot(53,34) . "<br>";
echo hypot(0,6) . "<br>";
echo hypot(5,3) . "<br>";
echo sqrt(2*8+9*4);
?>
Output
62.968245965725
6
5.8309518948453
7.211102550928
23. intdiv :-
It is used to return the integer quotient of the given division.
<?php
$dividend = 105;
$divisor = 3;
echo intdiv($dividend, $divisor);
?>
Output
35
24. is_finite :-
It is used to check whether the value is defined (fixed) or not.
<?php
echo is_finite(23) . "<br>";
echo is_finite(log(90)) . "<br>";
echo is_finite(7300);
?>
Output
1
1
1
25. is_infinite :-
It is used to check whether the value is incalculable (infinite) or not.
<?php
echo is_infinite(7) . "<br>";
echo is_infinite(log(0)) . "<br>";
echo is_infinite(2760);
?>
Output
1
26. is_nan:-
It is used to check whether the value is not-a-number.
<?php
echo is_nan(780) . "<br>";
echo is_nan(-810) . "<br>";
echo is_nan(acos(10.91));
?>
Output
1
27. lcg_value :-
It is used to return a pseudo number in the circle of 0 and 1.
<?php
echo lcg_value();
echo "<br>";
echo lcg_value();
echo "<br>";
echo lcg_value();
?>
Output
0.40787849243462
0.13174943472801
0.95245177147425
28. log10 :-
It is used to return the logarithm to base-10 of distinct number.
<?php
echo(log10(21.8300) . "<br>");
echo(log10(28) . "<br>");
echo(log10(10) . "<br>");
echo(log10(0));
?>
Output
1.3390537357091
1.4471580313422
1
-INF
29. log1p :-
It is used to return the log(1+number) for distinct numbers.
<?php
echo(log1p(12.1809) . "<br>");
echo(log1p(20) . "<br>");
echo(log1p(-1) . "<br>");
echo(log1p(0));
?>
Output
2.5787688120238
3.0445224377234
-INF
0
30. log :-
It is used to return the common logarithm of distinct numbers.
<?php
echo(log(12.1809) . "<br>");
echo(log(20) . "<br>");
echo(log(-1) . "<br>");
echo(log(0));
?>
Output
2.4998691511775
2.995732273554
NAN
-INF
31. max :-
It is used to find the highest value of a given number.
<?php
echo(max(12,48,6,80,190) . "<br>");
echo(max(222,14,608,318,175) . "<br>");
echo(max(array(-4,96,88,10)) . "<br>");
echo(max(array(-44,-106,851,192)));
?>
Output
190
608
96
851
32. min :-
It is used to find the lowest value of a given number.
<?php
echo(min(12,48,6,80,190) . "<br>");
echo(min(222,14,608,318,175) . "<br>");
echo(min(array(-4,96,88,10)) . "<br>");
echo(min(array(-44,-106,851,192)));
?>
Output
6
14
-4
-106
33. mt_getrandmax :-
It is used return the largest random value.
<?php
echo(mt_getrandmax());
?>
Output
2147483647
34. mt_rand :-
It is used to generate a random number.
<?php
echo(mt_rand() . "<br>");
echo(mt_rand() . "<br>");
echo(mt_rand(90,700));
?>
Output
213668980
136014420
463
35. mt_srand :-
It is used to start a random number generator.
<?php
mt_srand(time());
echo(mt_rand());
?>
Output
1620125873
36. octdec :-
It is used to convert the octal number into decimal.
<?php
echo octdec("39") . "<br>";
echo octdec("120") . "<br>";
echo octdec("5630") . "<br>";
echo octdec("196");
?>
Output
3
80
2968
14
37. pi :-
It returns the value of PI.
<?php
echo(pi());
?>
Output
3.1415926535898
38. pow :-
It is used to calculate the base produced by the power of an exponent.
<?php
echo(pow(22,9) . "<br>");
echo(pow(-5,7) . "<br>");
echo(pow(-2,-6) . "<br>");
echo(pow(-2,-4.8));
?>
Output
1207269217792
-78125
0.015625
NAN
39. rad2deg :-
It is used to convert the radians into degrees.
<?php
echo rad2deg(pi()) . "<br>";
echo rad2deg(pi()/8);
?>
Output
180
22.5
40. rand :-
It is used to generate a random integer number.
<?php
echo(rand() . "<br>");
echo(rand() . "<br>");
echo(rand(16,800));
?>
Output
974009498
1206875055
109
41. round :-
It is used to round the float number and return an integer.
<?php
echo(round(30.67) . "<br>");
echo(round(70.880) . "<br>");
echo(round(05.99) . "<br>");
echo(round(-4.70) . "<br>");
echo(round(-44.60));
?>
Output
31
71
6
-5
-45
42. sin :-
It is used to return the sine of distinct number.
<?php
echo(sin(7) . "<br>");
echo(sin(-2) . "<br>");
echo(sin(0) . "<br>");
echo(sin(10) . "<br>");
echo(sin(M_PI) . "<br>");
echo(sin(M_PI_2));
?>
Output
0.65698659871879
-0.90929742682568
0
-0.54402111088937
1.2246467991474E-16
1
43. sinh :-
It is used to return the hyperbolic sine of distinct number.
<?php
echo(sinh(7) . "<br>");
echo(sinh(-2) . "<br>");
echo(sinh(0) . "<br>");
echo(sinh(10) . "<br>");
echo(sinh(M_PI) . "<br>");
echo(sinh(M_PI_2));
?>
Output
548.31612327325
-3.626860407847
0
11013.232874703
11.548739357258
2.3012989023073
44. sqrt :-
It is used to find the square root of a given number.
<?php
echo(sqrt(0) . "<br>");
echo(sqrt(1) . "<br>");
echo(sqrt(5) . "<br>");
echo(sqrt(10) . "<br>");
echo(sqrt(0.580) . "<br>");
echo(sqrt(-0.7) . "<br>");
echo(sqrt(-9));
?>
Output
0
1
2.2360679774998
3.1622776601684
0.76157731058639
NAN
NAN
45. srand :-
It begins with a random number generate.
<?php
srand(time());
echo(rand());
?>
Output
1683031199
46. tan :-
It is used to return the tangent of distinct numbers.
<?php
echo(tan(M_PI_4) . "<br>");
echo(tan(0.90) . "<br>");
echo(tan(-0.20) . "<br>");
echo(tan(9) . "<br>");
echo(tan(35) . "<br>");
echo(tan(-2) . "<br>");
echo(tan(-100));
?>
Output
1
1.2601582175503
-0.20271003550867
-0.45231565944181
0.47381472041445
2.1850398632615
0.58721391515693
47. tanh :-
It is used to return the hyperbolic tangent of distinct numbers.
<?php
echo(tanh(M_PI_4) . "<br>");
echo(tanh(0.90) . "<br>");
echo(tanh(-0.20) . "<br>");
echo(tanh(9) . "<br>");
echo(tanh(35) . "<br>");
echo(tanh(-2) . "<br>");
echo(tanh(-100));
?>
Output
0.65579420263267
0.71629787019902
-0.1973753202249
0.99999996954004
1
-0.96402758007582
-1