Content · Programming · PHP

PHP deg2rad() Function: Usage and Examples

Learn how PHP deg2rad works with practical examples, important behavior, relevant alternatives and common mistakes.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Converts an angle from degrees to radians.

What Is deg2rad() in PHP?

Converts an angle from degrees to radians.

Its syntax is:

deg2rad(float $num): float

Parameters:

  • $num — Accepted as float; required argument.

Return type: float. Trigonometric functions such as sin() expect radians, not degrees.

Availability: Core PHP.

Example 1: Basic Usage

<?php

echo round(deg2rad(180), 4);

Output:

3.1416

Trigonometric functions such as sin() expect radians, not degrees.

Example 2: A Different Input

<?php

echo round(deg2rad(90), 4);

Output:

1.5708

Trigonometric functions such as sin() expect radians, not degrees.

Practical Example: Applying It in a Program

<?php

$anglesInDegrees = [0, 45, 90]; foreach ($anglesInDegrees as $angle) { echo round(sin(deg2rad($angle)), 4) . PHP_EOL; }

Output:

0
0.7071
1

Trigonometric functions such as sin() expect radians, not degrees.

Important Behavior and Edge Cases

  • Key behavior: Trigonometric functions such as sin() expect radians, not degrees.
  • Environment: Core PHP.

Comparison With Related Functions

FunctionPurpose
deg2rad()Converts an angle from degrees to radians.
rad2deg()rad2deg() converts radians to degrees; deg2rad() converts degrees to radians.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: Trigonometric functions such as sin() expect radians, not degreesTrigonometric functions such as sin() expect radians, not degrees.

Key Takeaways

  • Converts an angle from degrees to radians.
  • Trigonometric functions such as sin() expect radians, not degrees.
  • Core PHP.

Summary: Trigonometric functions such as sin() expect radians, not degrees.

Share this resourceSend this page to someone who may find it useful.