• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

PHP cos function – Cosine

by admin

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); 

Filed Under: PHP

Some more articles you might also be interested in …

  1. PHP function bin2hex – Convert binary data into hexadecimal representation
  2. PHP function abs – Absolute value
  3. PHP function str_repeat() – Repeat a string
  4. PHP addslashes function – Quote string with slashes
  5. PHP function stripcslashes() – Un-quote string quoted with addcslashes()
  6. PHP function stripslashes() – Un-quotes a quoted string
  7. PHP function strcmp() – Binary safe string comparison
  8. PHP asin function – Arc sine
  9. PHP Function strchr() – Alias of strstr()
  10. How to test a PHP script

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright