PHP cos() Function

Definition and Usage

The cos() function returns the cosine ratio of given angle in radians. In trigonometry, cosine of an angle is defined as ratio of lengths of adjacent side and hypotenuse.

cos(x) = adjacent/hypotenuse

If x=90 degree, cos(x) = 0.

This function returns a float value.

Syntax

cos ( float $arg ) : float

Parameters

Sr.No Parameter & Description
1 arg
A floating point value that represents angle in radians

Return Values

PHP cos() function returns cosine ratio of given parameter.

PHP Version

This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.

Example

<?php
   $arg=M_PI;
   $val=cos($arg);
   echo "cos(" . $arg . ") = " . $val;
?>

Output

This will produce following result −

cos(3.1415926535898) = -1
Updated on: 2026-03-11T23:22:53+05:30

388 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements