PHP Tutorial - 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  .j  a  v  a2 s .  c  o 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.