PHP cos() Function

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 ValueThe cosine of number
Return TypeFloat

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//from  ww  w  .  j a  v a2 s .  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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions