rad2deg() converts an angle measured in radians to degrees, which is often easier to display to users.
$radians = pi() / 2;
echo rad2deg($radians); // 90
<?Php
echo rad2deg(0); // Output is 0
echo "<br>";
echo rad2deg(PI()); // Output 180
echo "<br>";
echo rad2deg(PI()/2); // Output is 90
echo "<br>";
echo rad2deg(PI()/3); // Output is 60
?>
Syntax
float rad2deg(float $radians);
$radians is the angle measured in radians. The returned float is the equivalent angle in degrees.<?php
echo rad2deg(2 * M_PI); // Output: 360
?>
<?php
echo rad2deg(-M_PI); // Output: -180
?>
<?php
echo rad2deg(0.1); // Output: 5.7295779513
?>
<?php
echo rad2deg(M_PI); // Output: 180
?>
<?php
$degrees = 45;
$radians = deg2rad($degrees);
echo rad2deg($radians); // Output: 45
?>
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.