PHP sqrt() Function
The PHP sqrt() function returns the square root of the given number. In special cases it returns the following:
- If the argument is NAN or less than zero, then the result is NAN.
- If the argument is positive infinity, then the result is positive infinity.
Syntax
sqrt(number)
Parameters
number |
Required. Specify a number. |
Return Value
Returns the square root of the specified number (returns NAN for negative number).
Example:
In the example below, sqrt() function is used to find out the square root of the given number.
<?php echo "sqrt(4) = ".sqrt(4)."\n"; echo "sqrt(25) = ".sqrt(25)."\n"; echo "sqrt(50) = ".sqrt(50)."\n"; echo "sqrt(-50) = ".sqrt(-50)."\n"; echo "sqrt(INF) = ".sqrt(INF)."\n"; echo "sqrt(-INF) = ".sqrt(-INF)."\n"; echo "sqrt(NAN) = ".sqrt(NAN)."\n"; ?>
The output of the above code will be:
sqrt(4) = 2 sqrt(25) = 5 sqrt(50) = 7.0710678118655 sqrt(-50) = NAN sqrt(INF) = INF sqrt(-INF) = NAN sqrt(NAN) = NAN
❮ PHP Math Reference