sin() function in PHP

The sin() function in PHP returns the sine of a number. It accepts a numeric value in radians and returns the corresponding sine value as a floating-point number.

Syntax

sin(number)

Parameters

  • number − A numeric value in radians for which you want to calculate the sine.

Return Value

The sin() function returns the sine of the given number as a float. The return value ranges between -1 and 1.

Example 1

Here's a basic example demonstrating the sin() function with different radian values −

<?php
    echo sin(0.50) . "<br>";
    echo sin(-0.90) . "<br>";
    echo sin(M_PI/2) . "<br>";  // 90 degrees
?>
0.4794255386042
-0.78332690962748
1

Example 2

Let's see more examples with common radian values −

<?php
    echo "sin(0) = " . sin(0) . "<br>";
    echo "sin(1) = " . sin(1) . "<br>";
    echo "sin(-1) = " . sin(-1) . "<br>";
    echo "sin(?) = " . sin(M_PI) . "<br>";
?>
sin(0) = 0
sin(1) = 0.8414709848079
sin(-1) = -0.8414709848079
sin(?) = 1.2246467991474E-16

Key Points

  • The input must be in radians, not degrees
  • Use deg2rad() function to convert degrees to radians if needed
  • The function returns values between -1 and 1
  • Use M_PI constant for ? (pi) calculations

Conclusion

The sin() function is essential for trigonometric calculations in PHP. Remember that it works with radians, and you can use PHP's built-in constants like M_PI for precise mathematical operations.

Updated on: 2026-03-15T07:30:11+05:30

110 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements