What is acos() in PHP?

The acos()also called the “arc cosine” function function in PHP returns the inverse cosine of a number. To be more specific, acos() returns the inverse cosine of a number in radians.

Figure 1 below shows the mathematical representation of the acos() function.

Figure 1: Mathematical representation of inverse cosine function

Methodology

To convert radians to degrees, use the following formula.


degrees = radians * ( 180.0 / M_PI)

Syntax


float acos(num)

Parameter

The acos() function requires a number as a parameter.

Return value

acos() returns the inverse cosine of a number that is sent as a parameter in radians. The return value lies within the interval of [0, pi] radians.

Code

<?php
#Positive number in radians
echo("acos(0.5): ");
echo (acos(0.5));
echo(" Radians")
?>
<?php
#Negative number in radians
echo("acos(-0.5): ");
echo (acos(-0.5));
echo(" Radians")
?>
<?php
#applying acos() and then converting the result in radians to degrees
#radians = 0.5
echo("acos(0.5) * (180.0 / M_PI)): ");
echo (acos(0.5) * (180.0 / M_PI));
echo(" Degrees")
?>

Free Resources

Attributions:
  1. undefined by undefined