Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
math
tangent
communitycreator

What is tan() in PHP?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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

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))));
?>

RELATED TAGS

php
math
tangent
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring