Introduction
As you know PHP is a sever side script language which is used for creating dynamic web pages. In PHP you can use mathematical functions. There are various mathematical functions in PHP. There are PHP math functions to take care of addition, subtraction, division and multiplication and many other mathematical requirements. PHP has nice support for mathematical processing. Some examples of mathematical functions in PHP are as follows:
1. abs () function
The abs() function returns the absolute value of a number. The example of the abs() function is as follows:
<html>
<body bgcolor="pink"><h3>abs function</h3>$num=-10;echo "Your number is : $num".'
';echo "Using abs function your number is : ".abs ($num);?></body></html>
Output<body bgcolor="pink"><h3>abs function</h3>$num=-10;echo "Your number is : $num".'
';echo "Using abs function your number is : ".abs ($num);?></body></html>
2. dechex () function
The dechex() function is used to convert the decimal number to a hexadecimal number. The example of hecdex() function is as follows:
<html>
<body bgcolor="pink"><h3>dechex function</h3>$num=525;echo "Your number is : $num".'
';echo "Using dechex function your number is : ".dechex ($num);?></body>}</html>
Output<body bgcolor="pink"><h3>dechex function</h3>$num=525;echo "Your number is : $num".'
';echo "Using dechex function your number is : ".dechex ($num);?></body>}</html>
3. sqrt() function
The sqrt() function is used to get the square root of a number. The example of the sqrt() function is as follows:
<body bgcolor="pink"><h3>sqrt function</h3>$num=625;echo "Your number is : $num".'
';echo "Using sqrt function your number is : ".sqrt ($num);?></body>
4. log() function
The log() function is used to get the log value of a number. The example of the log() function is as follows:
<body bgcolor="pink"><h3>log function</h3>$num=10;echo "Your number is : $num".'
';echo "Using log function your number is : ".log ($num);?></body>
5. floor() function
In the floor() function we use a float or real number. The floor() function returns the nearest value of an integer. The example of the floor() function is as follows:
<html>
<body bgcolor="pink"><h3>floor function</h3>$num=5.89;echo "Your number is : $num".'
';echo "Using floor function your number is : ".floor ($num).'
';?></body></html>
Output<body bgcolor="pink"><h3>floor function</h3>$num=5.89;echo "Your number is : $num".'
';echo "Using floor function your number is : ".floor ($num).'
';?></body></html>
6. ceil() function
In the ceil() function we use a float or real number. The ceil() function returns the nearest value of an integer. The example of the ceil() function is as follows:
<html>
<body bgcolor="pink"><h3>ceil function</h3>$num=5.89;echo "Your number is : $num".'
';echo "Using ceil function your number is : ".ceil ($num).'
';?></body></html>
Output<body bgcolor="pink"><h3>ceil function</h3>$num=5.89;echo "Your number is : $num".'
';echo "Using ceil function your number is : ".ceil ($num).'
';?></body></html>
7. pow() function
The pow() is used to calculate the power of any number. The example of the pow() is as follows:
<html>
<body bgcolor="pink"><h3>pow function</h3>$num=5;echo "Your number is : $num".'
';echo "Using pow function your number is : ".pow(2,$num).'
';echo "Using pow function your number is : ".pow($num,2);?></body></html>
Output<body bgcolor="pink"><h3>pow function</h3>$num=5;echo "Your number is : $num".'
';echo "Using pow function your number is : ".pow(2,$num).'
';echo "Using pow function your number is : ".pow($num,2);?></body></html>
8. max() and min() function
The max() function is used to calculate the maximum number of various numbers. The min() function is used to calculate minimum number of various numbers. The example of the max() and min() functions is as follows:
<html>
<body bgcolor="pink"><h3>max and min function</h3>$num=array(2,6,10,3,15);Echo "Your number are :" ." ". $num[0].",".$num[1].",".$num[2].",".$num[3].",".$num[4].'
';echo "Maximum number is : ".max ($num).'
';echo "Minimum number is : ".min ($num);?></body></html>
Output<body bgcolor="pink"><h3>max and min function</h3>$num=array(2,6,10,3,15);Echo "Your number are :" ." ". $num[0].",".$num[1].",".$num[2].",".$num[3].",".$num[4].'
';echo "Maximum number is : ".max ($num).'
';echo "Minimum number is : ".min ($num);?></body></html>
Geometric Functions
1. sin() function
The sin() function is used to calculate the sine value of a given number. The example of the sin() function is as follows:
<body bgcolor="pink"><h3>sin() function</h3>$num=0;Echo "The value of angle : $num".'
';echo "The value of sin0 is : ".sin($num);?></body>
2. cos() function
The cos() function is used to calculate the cosine value of a given number. The example of the cos() function is as follows:
<body bgcolor="pink"><h3>cos() function</h3>$num=0;Echo "The value of angle : $num".'
';echo "The value of cos0 is : ".cos($num);?></body>
3. tan() function
The tan() function is used to calculate the tangent value of a given number. The example of the tan() function is as follows:
<body bgcolor="pink"><h3>tan() function</h3>$num=45;Echo "The value of angle : $num".'
';echo "The value of tan45 is : ".tan ($num);?></body>
Similarly you can use more geometric function in PHP.
Conclusion
So in this article you saw how to use mathematical and geometric functions in PHP. Using this article one can easily understand the use of mathematical functions in PHP.
No comments:
Post a Comment