PHP deg2rad() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

The deg2rad() function converts an angle from degrees into radians.

PHP trigonometry functions like sin() and cos() expect radians, so you use deg2rad() when your angle is in degrees.

Syntax

Call deg2rad() with the values you need. Start with this line.

PHP
You pass an angle in degrees to deg2rad() and it returns the same angle in radians as a float.
CallWhat it does
deg2rad(180)Returns about 3.14159, which is pi.
deg2rad(90)Returns about 1.5708, which is pi divided by 2.
deg2rad(0)Returns 0.

The formula behind it is radians = degrees x pi / 180. It is the opposite of rad2deg().

Library declarations
PHP
deg2rad(float $num): float

Parameters

ParameterDescription
numRequired. The angle in degrees that you want to convert.

Return Value

Return ValueDescription
floatThe angle converted to radians.

PHP Examples

Example 1 — Convert common angles

Convert a few well known angles and round the results to four decimals.

PHP
<?php
echo round(deg2rad(180), 4) . PHP_EOL;
echo round(deg2rad(90), 4) . PHP_EOL;
echo round(deg2rad(45), 4) . PHP_EOL;

How It Works

  1. deg2rad(180) is the same as pi, which is 3.14159...
  2. deg2rad(90) is pi divided by 2.
  3. deg2rad(45) is pi divided by 4.
  4. round(..., 4) keeps four decimal places so the output is short and clean.

Example 2 — Zero, full circle and negative angles

See what happens at 0 degrees, 360 degrees and with a negative angle.

PHP
<?php
echo deg2rad(0) . PHP_EOL;
echo round(deg2rad(360), 4) . PHP_EOL;
echo round(deg2rad(-90), 4) . PHP_EOL;

How It Works

  1. deg2rad(0) is 0, and PHP prints a float zero as 0.
  2. A full circle of 360 degrees equals 2 x pi, about 6.2832 radians.
  3. A negative angle gives a negative radian value, which means turning the other way.
  4. deg2rad() does not wrap angles, so 360 stays 6.2832 and does not become 0.

Example 3 — Use degrees with sin() and cos()

Convert degrees first, then pass the result to the trigonometry functions.

PHP
<?php
$angle = 30;
echo "sin(30 deg) = " . round(sin(deg2rad($angle)), 2) . PHP_EOL;
echo "cos(60 deg) = " . round(cos(deg2rad(60)), 2) . PHP_EOL;
echo "sin(90 deg) = " . round(sin(deg2rad(90)), 2) . PHP_EOL;

How It Works

  1. sin() and cos() in PHP work with radians, not degrees.
  2. deg2rad() converts the degree value before it reaches sin() or cos().
  3. round(..., 2) hides tiny floating point errors such as 0.49999999999999994.
  4. The results match the values you know from math class: 0.5, 0.5 and 1.

Frequently Asked Questions

It converts an angle measured in degrees into radians. For example deg2rad(180) returns pi.
Because PHP trigonometry functions expect radians. Passing degrees directly gives wrong answers.
Use rad2deg(). For example rad2deg(M_PI) returns 180.
radians = degrees x pi / 180. PHP does this for you, so you do not need to write it by hand.
Floats store approximate values. Use round() to control how many decimals you show.

Next: exp()

The exp() function calculates e raised to the power of a number, where e is Euler's number.

exp() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful