What is tan() in PHP?

The tan() function in PHP returns the tangent of a number in radians.

The following illustration shows the mathematical representation of the tan() function.

Mathematical representation of tangent function

This tan() function only works for right-angled triangles.

Syntax

```php tan(float $num): float ```

Parameter

This function requires a number that represents an angle in radians as a parameter.

To convert degrees to radians, use the following formula:

radians = degrees * ( M_PI / 180.0 )

Return value

`tan()` returns the tangent of a number in *radians* that is sent as a parameter. * If positive/negative infinity or NaNnot a number is passed as an argument, the value returned is `NaN`.

Code

<?php
#Positive number in radians
echo("tan(2.3): ");
echo (tan(2.3));
?>
<?php
#Negative number in radians
echo("tan(-2.3): ");
echo (tan(-2.3));
?>
<?php
#converting the degrees angle into radians and then applying tan()
#degrees = 45
echo("tan(45 * (M_PI / (180))): ");
echo (tan(45 * (M_PI / (180))));
?>

Free Resources

Attributions:
  1. undefined by undefined