Open In App

PHP deg2rad() Function

Among the methods to measure angles, the two most commonly used are degrees and radians. Students typically learn about degree while learning about radian becomes a later concern. But there are certain cases where radian is the preferred unit of measurement such as:

Thus in some cases it is required to convert from degrees to radian, this is where the method deg2rad() comes in aid.



Syntax:

float deg2rad ($value)

Parameters: The function takes a single parameters which is a float that represents the angle in degrees.



Return Type: This function returns a float value that represents the radian equivalent of the angle.

Examples:

Input :  $deg = 45;
Output : 0.78539816339745

Input : $deg = 90;
Output : 1.5707963267949

Input : $deg = 180;
Output : 3.1415926535898
         

Below program illustrates the working of deg2rad() in PHP:




<?php
// PHP code to illustrate the working of deg2rad()
$deg = 22.5;
$k = 8;
for(;$k>=1;$k/=2, $deg*=2)
{
  if($k!=1)
   echo 'pi/'.$k.' = '.deg2rad($deg).'<br>';
  else
   echo 'pi = '.deg2rad($deg).'<br>';
}
  
?>

Output:

pi/8 = 0.39269908169872
pi/4 = 0.78539816339745
pi/2 = 1.5707963267949
pi = 3.1415926535898

Important points to note:

Reference:
http://php.net/manual/en/function.deg2rad.php

Article Tags :