The cos()
function in PHP calculates the cosine of a number in radians.
The following illustration shows the mathematical representation of the cos()
function.
Note: The
cos()
function only works for right-angled triangles.
float cos(num)
This function requires a number that represents an angle in radians as a parameter.
To convert degrees to radians, use the following formula.
radians = degrees * ( M_PI / 180.0 )
cos()
returns the cosine of a number that is sent as a parameter. The return value is in the range [-1,1].
<?php #Positive number in radians echo("cos(2.3): "); echo (cos(2.3)); ?> <?php #Negative number in radians echo("cos(-2.3): "); echo (cos(-2.3)); ?> <?php #converting the degrees angle into radians and then applying cos() #degrees = 180 echo("cos(180 * (M_PI / (180))): "); echo (cos(180 * (M_PI / (180)))); ?>
RELATED TAGS
CONTRIBUTOR
View all Courses