PHP cos() Function
The PHP cos() function returns trigonometric cosine of an angle (angle should be in radians). In special cases it returns the following:
- If the argument is NAN or an infinity, then the result is NAN.
In the graph below, cos(x) vs x is plotted.
Syntax
cos(number)
Parameters
number |
Required. Specify the angle in radian. |
Return Value
Returns the trigonometric cosine of an angle.
Example:
In the example below, cos() function is used to find out the trigonometric cosine of an angle.
<?php echo "cos(pi()/6) = ".cos(pi()/6)."\n"; echo "cos(pi()/4) = ".cos(pi()/4)."\n"; echo "cos(pi()/3) = ".cos(pi()/3)."\n"; echo "cos(deg2rad(45)) = ".cos(deg2rad(45))."\n"; echo "cos(M_PI/2) = ".cos(M_PI/2)."\n"; echo "cos(M_PI_4) = ".cos(M_PI_4)."\n"; echo "cos(NAN) = ".cos(NAN)."\n"; echo "cos(INF) = ".cos(INF)."\n"; ?>
The output of the above code will be:
cos(pi()/6) = 0.86602540378444 cos(pi()/4) = 0.70710678118655 cos(pi()/3) = 0.5 cos(deg2rad(45)) = 0.70710678118655 cos(M_PI/2) = 6.1232339957368E-17 cos(M_PI_4) = 0.70710678118655 cos(NAN) = NAN cos(INF) = NAN
❮ PHP Math Reference