Content · Programming · PHP

PHP atan() Function: Usage and Examples

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

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

Calculates the inverse tangent and returns an angle in radians.

What Is atan() in PHP?

Calculates the inverse tangent and returns an angle in radians.

Its syntax is:

atan(float $num): float

Parameters:

  • $num — Accepted as float; required argument.

Return type: float. The output is in radians. Convert with rad2deg() for display in degrees. For a point with x and y coordinates use atan2().

Availability: Available in standard PHP.

Example 1: Basic Usage

<?php

echo atan(0);

Output:

0

The output is in radians. Convert with rad2deg() for display in degrees. For a point with x and y coordinates use atan2().

Example 2: A Different Input

<?php

echo round(rad2deg(atan(1)), 1);

Output:

45

The output is in radians. Convert with rad2deg() for display in degrees. For a point with x and y coordinates use atan2().

Practical Example: Applying It in a Program

<?php

$slopes = [0, 1, 2];
foreach ($slopes as $slope) { echo round(rad2deg(atan($slope)), 2) . PHP_EOL; }

Output:

0
45
63.43

The output is in radians. Convert with rad2deg() for display in degrees. For a point with x and y coordinates use atan2().

Important Behavior and Edge Cases

  • Key behavior: The output is in radians. Convert with rad2deg() for display in degrees. For a point with x and y coordinates use atan2().
  • Environment: Available in standard PHP.

Comparison With Related Functions

FunctionPurpose
atan()calculates the inverse tangent and returns an angle in radians.
atan2()atan2() accepts separate y and x coordinates to determine a quadrant; atan() takes a single ratio.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring this behavior: The output is in radiansThe output is in radians. Convert with rad2deg() for display in degrees. For a point with x and y coordinates use atan2().

Key Takeaways

  • calculates the inverse tangent and returns an angle in radians.
  • The output is in radians. Convert with rad2deg() for display in degrees. For a point with x and y coordinates use atan2().
  • Available in standard PHP.

Summary: The output is in radians. Convert with rad2deg() for display in degrees. For a point with x and y coordinates use atan2().

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