cos()
calculates the cosine value.
PHP cos() Function has the following format.
float cos ( float num )
Parameter | Is Required | Description |
---|---|---|
number | Required. | A number |
The parameter should be passed as radians. We should use deg2rad() to convert degrees to radians.
Item | Description |
---|---|
Return Value | The cosine of number |
Return Type | Float |
The cos() function returns a numeric value between -1 and 1, which represents the cosine of the angle.
Return the cosine of different numbers:
<?php/* ww w . j a v a 2 s . c om*/
$cos1 = cos(10);
print($cos1);
echo("\n");
$cos2 = cos(deg2rad(80));
print($cos1);
echo("\n");
echo(cos(3) . "\n");
echo(cos(-3) . "\n");
echo(cos(0) . "\n");
echo(cos(M_PI) . "\n");
echo(cos(2*M_PI));
?>
The code above generates the following result.