take the cosine of a number in php

To take the cosine of a number in PHP, you can use the built-in cos() function. This function takes one parameter, which is the angle in radians.

Here's an example:

main.php
<?php
$angle = 45; // degrees
$angle_rad = deg2rad($angle);
$cos = cos($angle_rad);
echo $cos; // output: 0.70710678118655
?>
126 chars
7 lines

In this example, we start by defining the angle in degrees ($angle). We then convert it to radians using the deg2rad() function, since cos() expects the angle to be in radians. We pass the radian angle to cos() to get the cosine value, which we store in $cos. Finally, we output the result with echo.

gistlibby LogSnag