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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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 abs – Absolute value
  2. PHP function chr() – Generate a single-byte string from a number
  3. PHP bindec function – Convert a number between arbitrary bases
  4. PHP function stripcslashes() – Un-quote string quoted with addcslashes()
  5. PHP asin function – Arc sine
  6. PHP atan function – Arc tangent
  7. PHP function strcasecmp() – Binary safe case-insensitive string comparison
  8. PHP addslashes function – Quote string with slashes
  9. PHP function acos – Arc cosine
  10. “Access denied for user ‘username’@’hostname’ (using password: YES)” – Error while connecting MySQL with PHP

You May Also Like

Primary Sidebar

Recent Posts

  • nixos-rebuild Command Examples in Linux
  • nixos-option: Command Examples in Linux
  • nixos-container : Command Examples in Linux
  • nitrogen Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright