PHP sin() Function

The sin() function returns the sine of a given angle in radians. In trigonometry, sine of an angle is defined as the ratio of the length of the opposite side to the hypotenuse in a right triangle.

sin(x) = opposite/hypotenuse

For example, if x = 90 degrees (?/2 radians), sin(x) = 1, as the opposite side equals the hypotenuse in this case. This function returns a float value.

Syntax

sin(float $arg): float

Parameters

Parameter Description
arg A floating point value representing the angle in radians

Return Value

The function returns the sine of the given angle as a float value.

Examples

Basic Usage

Here's how to calculate sine of ? (180 degrees) ?

<?php
    $angle = M_PI; // ? radians (180 degrees)
    $result = sin($angle);
    echo "sin(" . $angle . ") = " . $result;
?>
sin(3.1415926535898) = 1.2246467991474E-16

Note: The result is very close to 0 (the expected value), with the small number due to floating-point precision.

Common Angles

Let's calculate sine for some common angles ?

<?php
    // Common angles in radians
    $angles = [0, M_PI/6, M_PI/4, M_PI/3, M_PI/2];
    $degrees = [0, 30, 45, 60, 90];
    
    for ($i = 0; $i < count($angles); $i++) {
        $sine = sin($angles[$i]);
        echo $degrees[$i] . "° = " . round($sine, 4) . "<br>";
    }
?>
0° = 0
30° = 0.5
45° = 0.7071
60° = 0.866
90° = 1

Converting Degrees to Radians

Since sin() expects radians, you can convert degrees using deg2rad() ?

<?php
    $degrees = 45;
    $radians = deg2rad($degrees);
    $sine = sin($radians);
    
    echo "sin({$degrees}°) = " . round($sine, 4);
?>
sin(45°) = 0.7071

Conclusion

The sin() function is essential for trigonometric calculations in PHP. Remember that it works with radians, so use deg2rad() when working with degrees. The function is available in all PHP versions.

Updated on: 2026-03-15T08:59:05+05:30

315 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements