PHP Function Reference

PHP tan() Function



The PHP tan() function returns trigonometric tangent of an angle (angle should be in radians). In special cases it returns the following:

  • If the argument is NAN or an infinity, then the result is NAN.

In the graph below, tan(x) vs x is plotted.

Tan Function

Syntax

tan(number)

Parameters

arg Required. Specify the angle in radian.

Return Value

Returns the trigonometric tangent of an angle.

Example:

In the example below, tan() function is used to find out the trigonometric tangent of an angle.

<?php
echo "tan(pi()/6) = ".tan(pi()/6)."\n";
echo "tan(pi()/4) = ".tan(pi()/4)."\n";
echo "tan(pi()/3) = ".tan(pi()/3)."\n"; 
echo "tan(deg2rad(45)) = ".tan(deg2rad(45))."\n";
echo "tan(M_PI/2) = ".tan(M_PI/2)."\n";
echo "tan(M_PI_4) = ".tan(M_PI_4)."\n"; 
echo "tan(NAN) = ".tan(NAN)."\n";
echo "tan(INF) = ".tan(INF)."\n";
?>

The output of the above code will be:

tan(pi()/6) = 0.57735026918963
tan(pi()/4) = 1
tan(pi()/3) = 1.7320508075689
tan(deg2rad(45)) = 1
tan(M_PI/2) = 1.6331239353195E+16
tan(M_PI_4) = 1
tan(NAN) = NAN
tan(INF) = NAN

❮ PHP Math Reference