PHP cos function – Cosine

Description

The cos() function calculates the cosine value of the number provided as its only parameter. The parameter should be passed as radians—you should use deg2rad() to convert degrees to radians.

$cos1 = cos(10);
$cos2 = cos(deg2rad(80));

Syntax:

cos(float $num): float

Parameters

Parameter Description
num An angle in radians

Return Values

Returns the cosine of num in radians.

Examples

Example 1:

echo cos(M_PI);

Output:

-1

Example 2:
Calculate the cosine of a value:

$rad = pi() / 2; 
echo "The cosine of $rad = ", cos($rad); 
Related Post