PHP cos() Function
In this chapter you will learn:
- Definition for PHP cos() Function
- Syntax for PHP cos() Function
- Parameter for PHP cos() Function
- Return for PHP cos() Function
- Example - Return the cosine of different numbers
Definition
cos()
calculates the cosine value.
Syntax
PHP cos() Function has the following format.
float cos ( float num )
Parameter
Parameter | Is Required | Description |
---|---|---|
number | Required. | A number |
The parameter should be passed as radians. We should use deg2rad() to convert degrees to radians.
Return
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.
Example
Return the cosine of different numbers:
<?php//j a v a 2s.c o m
$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.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP cosh() Function
- Syntax for PHP cosh() Function
- Parameter for PHP cosh() Function
- Return for PHP cosh() Function
- Example - Return the hyperbolic cosine of different numbers
Home » PHP Tutorial » PHP Math Functions