
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP tan() Function
Definition and Usage
The tan() function returns the tangent ratio of given angle in radians. In trigonometry, tangent of an angle is defined as ratio of lengths of opposite side and adjacent side.
tan(x) = opposite/adjacent
tangent of an angle is also defined as ratio of its sine and cosine
tan(x) = sin(x)/cos(x)
If x=45 degree, tan(x) = 1 as in a right angled traingle, opposite and adjacent sides are qual.
This function returns a float value.
Syntax
tan ( float $arg ) : float
Parameters
Sr.No | Parameter & Description |
---|---|
1 | arg A floating point value that represents angle in radians |
Return Values
PHP tan() function returns tangent ratio of given parameter.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example calculates tan(pi/2) and returns 1.6331239353195E+16 (very large number). tngent ratio of 90 deg is infinity −
<?php $arg=M_PI/2; //90 degree $val=tan($arg); echo "tan(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
tan(1.5707963267949) = 1.6331239353195E+16
Example
Following example uses deg2rad() function to convert degrees to radians and then computes tan(60). Result is 1.7320508075689 which is sqrt(3) −
<?php $arg=deg2rad(60); $val=tan($arg); echo "tan(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
tan(1.0471975511966) = 1.7320508075689
Example
Let's check find out tan(45) degrees. It returns 1 −
<?php $arg=M_PI/4; //45 deg $val=tan($arg); echo "tan(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
tan(0.78539816339745) = 1
Example
Following example computes tan(0) and returns 0
<?php $arg=0; $val=tan($arg); echo "tan(" . $arg . ") = " . $val; ?>
Output
This will produce following result −
tan(0) = 0
- Related Articles
- tan() function in PHP
- tan() function for complex number in C++
- PHP Function arguments
- PHP abs() Function
- PHP acos() Function
- PHP acosh() Function
- PHP asin() Function
- PHP asinh() Function
- PHP atan() Function
- PHP atan2() Function
- PHP atanh() Function
- PHP base_convert() Function
- PHP bindec() Function
- PHP ceil() Function
- PHP cos() Function
