Home >>PHP Math Functions >PHP cos() Function

PHP cos() Function

PHP cos() Function

PHP cos()function is used to find the cosine of the given input number. It accepts only a single parameter $number which is the number whose cosine is to be found. The input value must be in radians. It returns a float value between -1 and 1 as output.

Syntax:

  cos($number);

Parameter Values

Parameter Description
number This is a required parameter. This parameter defines the given input number.

Here is an example of cos() function in PHP:

<html>
<body>

<?php

echo cos(1)."<br>";
echo cos(-1)."<br>";

?>

</body>
</html>
Output:
0.54030230586814
0.54030230586814

Here is an another example of cos() function in PHP:

<html>
<body>

<?php
$pi = M_PI;  // M_PI is the value of PI(22/7)

echo cos(0)."<br>";
echo cos($pi/3)."<br>";
echo cos($pi/4)."<br>";
echo cos($pi)."<br>";
echo cos(2*$pi)."<br>";

?>

</body>
</html>
Output:
1
0.5
0.70710678118655
-1
1

No Sidebar ads