Content · Programming · PHP

PHP rad2deg() Function: Usage and Examples

Learn PHP rad2deg() through clear code examples, practical usage, important limitations and common mistakes.

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

rad2deg() converts an angle measured in radians to degrees. This guide explains the function with focused examples and the decisions that matter in real applications.

What Is rad2deg() in PHP?

Converts an angle measured in radians to degrees.

A typical call looks like this:

<?php

rad2deg($num);

The input arguments shown in the call identify the relevant connection, resource, value, path or configuration for the operation. Pay attention to argument order and to the return value demonstrated below.

Example 1: Basic Usage

This first example uses rad2deg() directly to demonstrate its basic purpose.

<?php

echo rad2deg(pi());

Output:

180

The returned value illustrates converts an angle measured in radians to degrees. It changes angle units, not the trigonometric function result itself.

Example 2: A Different Input or Option

The next example changes the input or option, showing another supported use of rad2deg().

<?php

echo rad2deg(pi() / 2);

Output:

90

The returned value illustrates converts an angle measured in radians to degrees. It changes angle units, not the trigonometric function result itself.

Practical Example: Applying the Function

In application code, rad2deg() belongs in a controlled workflow with input validation, a checked result and cleanup where needed.

<?php

$angle = atan2(1, 1); echo round(rad2deg($angle));

Output:

45

The returned value illustrates converts an angle measured in radians to degrees. It changes angle units, not the trigonometric function result itself.

Important Behavior and Edge Cases

  • Main behavior: Converts an angle measured in radians to degrees.
  • Important limitation: It changes angle units, not the trigonometric function result itself.
  • Requirements: This operation is available in standard PHP; validate inputs and handle failures where relevant.

Comparison With Related Functions

Function or ApproachWhen to Use It
rad2deg()Converts an angle measured in radians to degrees.
deg2radConverts degrees back to radians, the inverse of rad2deg().

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring the specific limits or preconditions of rad2deg().It changes angle units, not the trigonometric function result itself.
Assuming every environment produces the same result.This operation is available in standard PHP; validate inputs and handle failures where relevant.

Key Takeaways

  • Converts an angle measured in radians to degrees.
  • It changes angle units, not the trigonometric function result itself.
  • This operation is available in standard PHP; validate inputs and handle failures where relevant.

Use rad2deg() when its behavior matches your task, and verify the relevant return value before taking further action. The output depends on the local configuration when it uses resources, files or an interactive terminal.

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