## Definition and Usage

Most trigonometric functions like sin, cos, tan etc require angle argument in radians. The deg2rad() function proves useful in conversion of degrees to radians.

This function returns a float number such that number=deg2rad(x) where is angle in degrees. angle in radian = angle in deg *180/pi

deg2rad ( float $number ) : float ## Parameters Sr.NoParameter & Description 1number A float number reprsenting angle in degrees ## Return Values PHP deg2rad() function returns a float number that represents angle in radians. ## PHP Version This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x. ## Example Live Demo Following example calculates radian equivalent of 30 degrees − <?php$arg=30;
$val=deg2rad($arg);
echo "deg2rad(" . $arg . ") = " .$val;
?>

## Output

This will produce following result −

deg2rad(30) = 0.5235987755983

## Example

Live Demo

Following example converts 180 deg in radians. We can confirm the result by comparing with value of M_PI. −

<?php
$arg=180;$val=deg2rad($arg); echo "deg2rad(" .$arg . ") = " . $val . ""; echo "pi in radians = ". M_PI; ?> ## Output This will produce following result − deg2rad(180) = 3.1415926535898 pi in radians = 3.1415926535898 ## Example Live Demo Non numeric argument produces error: − <?php$arg="Hello";
$val=deg2rad($arg);
echo "deg2rad(" . $arg . ") = " .$val;
?>

## Output

This will produce following result −

PHP Warning: deg2rad() expects parameter 1 to be float, string given

## Example

Live Demo

The argument number can be a binary, octal or hexadecimal decimal number. Following example converts 0x2d angle (equal to 45 degrees) to radians.

<?php
$arg=0x2d;$val=deg2rad($arg); echo "deg2rad(" .$arg . ") = " . \$val;
?>

## Output

This will produce following result −

deg2rad(45) = 0.78539816339745