PHP acos() Function

Definition

The acos() function calculates the arc cosine value, essentially reversing the operation of cos().

Syntax

PHP acos() Function has the following format.

float acos ( float num )

Parameter

ParameterDescription
numRequired. A number in range -1 to 1

Return

acos(-1) returns the value of Pi.

The return value is in radians, you should use the rad2deg() to convert radians to degrees.

PHP acos() function returns NAN if number is not in the range -1 to 1.

Example

Calculate the arc cosine value


<?php/*  w w  w . ja v a  2s  .  co  m*/
$acos1 = acos(0.4346);
print($acos1);
print "\n";
$acos2 = acos(cos(80));
print($acos2);
print "\n";
echo(acos(0.64) . "\n");
echo(acos(-0.4) . "\n");
echo(acos(0) . "\n");
echo(acos(-1) . "\n");
echo(acos(1) . "\n");
echo(acos(2));
?>

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