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
| Function | Purpose |
|---|---|
deg2rad() | Converts an angle from degrees to radians. |
rad2deg() | rad2deg() converts radians to degrees; deg2rad() converts degrees to radians. |
Common Beginner Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring this behavior: Trigonometric functions such as sin() expect radians, not degrees | Trigonometric 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.