# Trigonometric Functions in PHP

## PHP `sin()` Function

### PHP `sin()` Usage

The PHP `sin()` function will give you the sine of the `arg` parameter. The `arg` parameter is in radians.

### PHP `sin()` Syntax

`` sin ( float \$arg ) : float``

### PHP `sin()` Parameters

1. `arg` — A value in radians

### PHP `sin()` Return Value

The PHP `sin()` function returns the sine of `arg`

### PHP `sin()` Working Examples

#### 1. sin() example

``````<?php
// Precision depends on your precision directive
echo sin(deg2rad(60));  //  0.866025403 ...
echo sin(60);           // -0.304810621 ...
?>``````

## PHP `cos()` Function

### PHP `cos()` Usage

The PHP `cos()` function will give you the cosine of the `arg` parameter. The `arg` parameter is in radians.

### PHP `cos()` Syntax

`` cos ( float \$arg ) : float``

### PHP `cos()` Parameters

1. `arg` — An angle in radians

### PHP `cos()` Return Value

The PHP `cos()` function returns the cosine of `arg`

### PHP `cos()` Working Examples

#### 1. cos() example

``````<?php
echo cos(M_PI); // -1
?>``````

## PHP `tan()` Function

### PHP `tan()` Usage

The PHP `tan()` function will give you the tangent of the `arg` parameter. The `arg` parameter is in radians.

### PHP `tan()` Syntax

`` tan ( float \$arg ) : float``

### PHP `tan()` Parameters

1. `arg` — The argument to process in radians

### PHP `tan()` Return Value

The PHP `tan()` function returns the tangent of `arg`

### PHP `tan()` Working Examples

#### 1. tan() example

``````<?php
echo tan(M_PI_4); // 1
?>``````

## PHP `asin()` Function

### PHP `asin()` Usage

The PHP `asin()` function will give you the arc sine of `arg` in radians. `asin()` is the inverse function of `sin()`, which means that a==sin(asin(a)) for every value of a that is within `asin()`‘s range.

### PHP `asin()` Syntax

`` asin ( float \$arg ) : float``

### PHP `asin()` Parameters

1. `arg` — The argument to process

### PHP `asin()` Return Value

The PHP `asin()` function returns the arc sine of `arg` in radians

## PHP `acos()` Function

### PHP `acos()` Usage

The PHP `acos()` function will give you the arc cosine of `arg` in radians. `acos()` is the inverse function of `cos()`, which means that a==cos(acos(a)) for every value of a that is within `acos()`‘ range.

### PHP `acos()` Syntax

`` acos ( float \$arg ) : float``

### PHP `acos()` Parameters

1. `arg` — The argument to process

### PHP `acos()` Return Value

The PHP `acos()` function returns the arc cosine of `arg` in radians.

## PHP `atan()` Function

### PHP `atan()` Usage

The PHP `atan()` function will give you the arc tangent of `arg` in radians. `atan()` is the inverse function of `tan()`, which means that a==tan(atan(a)) for every value of a that is within `atan()`‘s range.

### PHP `atan()` Syntax

`` atan ( float \$arg ) : float``

### PHP `atan()` Parameters

1. `arg` — The argument to process

### PHP `atan()` Return Value

The PHP `atan()` function returns the arc tangent of `arg` in radians.

### Additional Tips from Fellow Developers

Contributed By: Anonymous

``````Contrary to the current description, it should hold y == tan(atan(y)) for ALL  y.
However, x == atan(tan(x)) only holds for those x which are in the range of atan, which are those x with -pi/2 < x < pi/2.
Of course, those equalities are limited by precision. On my machine
tan(atan(1000)) returns 1000.0000000001.
atan(tan(0)) returns 0 (correct).
atan(tan(M_PI)) returns -1.2246467991474E-16 instead of 0.``````

## PHP `atan2()` Function

### PHP `atan2()` Usage

The PHP `atan2()` function will this function calculates the arc tangent of the two variables `x` and `y`. It is similar to calculating the arc tangent of `y` / `x`, except that the signs of both arguments are used to determine the quadrant of the result.

### PHP `atan2()` Syntax

`` atan2 ( float \$y , float \$x ) : float``

### PHP `atan2()` Parameters

1. `y` — Dividend parameter

2. `x` — Divisor parameter

### PHP `atan2()` Return Value

The PHP `atan2()` function returns the arc tangent of `y`/`x` in radians.

### Additional Tips from Fellow Developers

Contributed By: reubs

``````Just a note:
PHP's atan2 function receives parameters in (y,x) and Excel receives it in (x,y) format. Just in case you are porting formulas across. :)``````

## PHP `asinh()` Function

### PHP `asinh()` Usage

The PHP `asinh()` function will give you the inverse hyperbolic sine of `arg`, i.e. the value whose hyperbolic sine is `arg`.

### PHP `asinh()` Syntax

`` asinh ( float \$arg ) : float``

### PHP `asinh()` Parameters

1. `arg` — The argument to process

### PHP `asinh()` Return Value

The PHP `asinh()` function returns the inverse hyperbolic sine of `arg`

### Changelog for PHP asinh() Function

5.3.0 — This function is now available on all platforms

## PHP `acosh()` Function

### PHP `acosh()` Usage

The PHP `acosh()` function will give you the inverse hyperbolic cosine of `arg`, i.e. the value whose hyperbolic cosine is `arg`.

### PHP `acosh()` Syntax

`` acosh ( float \$arg ) : float``

### PHP `acosh()` Parameters

1. `arg` — The value to process

### PHP `acosh()` Return Value

The PHP `acosh()` function returns the inverse hyperbolic cosine of `arg`

### Changelog for PHP acosh() Function

5.3.0 — This function is now available on all platforms

## PHP `atanh()` Function

### PHP `atanh()` Usage

The PHP `atanh()` function will give you the inverse hyperbolic tangent of `arg`, i.e. the value whose hyperbolic tangent is `arg`.

### PHP `atanh()` Syntax

`` atanh ( float \$arg ) : float``

### PHP `atanh()` Parameters

1. `arg` — The argument to process

### PHP `atanh()` Return Value

The PHP `atanh()` function returns inverse hyperbolic tangent of `arg`

### Changelog for PHP atanh() Function

5.3.0 — This function is now available on all platforms

## PHP `deg2rad()` Function

### PHP `deg2rad()` Usage

The PHP `deg2rad()` function will converts the number in degrees to the radian equivalent .

### PHP `deg2rad()` Syntax

`` deg2rad ( float \$number ) : float``

### PHP `deg2rad()` Parameters

1. `number` — Angular value in degrees

### PHP `deg2rad()` Return Value

The PHP `deg2rad()` function returns the radian equivalent of `number`

### PHP `deg2rad()` Working Examples

#### 1. deg2rad() example

``````<?php
echo deg2rad(45); // 0.785398163397
var_dump(deg2rad(45) === M_PI_4); // bool(true)
?>``````

## PHP `rad2deg()` Function

### PHP `rad2deg()` Usage

The PHP `rad2deg()` function will converts the radian number to the equivalent number in degrees .

### PHP `rad2deg()` Syntax

`` rad2deg ( float \$number ) : float``

### PHP `rad2deg()` Parameters

1. `number` — A radian value

### PHP `rad2deg()` Return Value

The PHP `rad2deg()` function returns the equivalent of `number` in degrees

### PHP `rad2deg()` Working Examples

#### 1. rad2deg() example

``````<?php
echo rad2deg(M_PI_4); // 45
?>``````

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments