PHP acos() Function

In this chapter you will learn:

  1. Definition for PHP acos() Function
  2. Syntax for PHP acos() Function
  3. Parameter for PHP acos() Function
  4. Return for PHP acos() Function
  5. Example - Calculate the arc cosine value

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/*from j  av a 2  s .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.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP acosh() Function
  2. Syntax for PHP acosh() Function
  3. Parameter for PHP acosh() Function
  4. Return for PHP acosh() Function
  5. Example - calculate the inverse hyperbolic cosine