take the cotangent of a number in php

To take cotangent of a number in PHP, you can use the tan() function along with the formula:

main.php
cot(x) = 1 / tan(x)
20 chars
2 lines

where x is the angle in radians.

Here's an example code snippet:

main.php
$angle = deg2rad(45); // convert degrees to radians
$cot = 1 / tan($angle);
echo "cotangent of ".$angle." radians is ".$cot;
125 chars
4 lines

This will output:

main.php
cotangent of 0.78539816339745 radians is 0.99999999999968
58 chars
2 lines

You can substitute $angle with your desired angle in radians to compute its cotangent.

gistlibby LogSnag