Categories
PHP Tips & Tutorials

PHP: Convert Degrees to Radians and Convert Radians to Degrees

Degrees and radians are different metric means to gauge an angle. They are mutually convertible in PHP. Simply use the PHP degrees to radians function deg2rad() and PHP radians to degrees function rad2deg().

$degrees = 180;
$radians = deg2rad($degrees); // 3.1416
$degrees = rad2deg($radians); // 180

Because trigonometric calculations are usually done in radians, you have to convert the degrees into radians:

$cosine = cos(deg2rad($degrees));

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.