Home >>PHP Math Functions >PHP sqrt() Function

PHP sqrt() Function

PHP sqrt() Function

PHP sqrt() function is used to calculate the square root of a given input number. It accepts only a single parameter $number which is the number whose square root is to be found. It returns a floating point value as output which is the square root of the given input argument $number passed to it.

Syntax:

  sqrt($number);

Parameter Values

Parameter Description
number This is a required parameter. This parameter defines the number passes as argument.

Here is an example of sqrt() function in PHP:

<html>
<body>

<?php

echo sqrt(0)."<br>";
echo sqrt(1)."<br>";
echo sqrt(4)."<br>";
echo sqrt(9)."<br>";
echo sqrt(16)."<br>";

?>

</body>
</html>
Output:
0
1
2
3
4

Here is another example of sqrt() function in PHP:

<html>
<body>

<?php

echo sqrt(5)."<br>";
echo sqrt(25)."<br>";
echo sqrt(-25)."<br>";  // square root of negative number is NAN.
echo sqrt(256)."<br>";
echo sqrt(56620.2025)."<br>";

?>

</body>
</html>
Output:
2.2360679774998
5
NAN
16
237.95