Converting from degrees to radians and vice versa
Unlike many other programming languages php actually has two bult in functions for dealing with radians to degrees and degrees to radians conversions these are rad2deg and deg2rad .
In this simple little example we will show you how to use this time saving pair of functions .
Code :
<?php
$number = 0.986;
$degrees = 32;
//get the cosine of $number
$cos_number = cos($number);
//display the cosine of $number
echo "the cosine of " . $number ." is " . $cos_number;
echo "<br>";
//convert $cos_number to degrees
echo "convert to degrees " . rad2deg($cos_number);
echo "<br>";
//convert $degrees to radians
echo "convert $degrees to radians = " . deg2rad($degrees);
?>
Example :
the cosine of 0.986 is 0.552029566065 convert to degrees 31.628964302 convert 32 to radians = 0.558505360638 |