PHP - sqrt() Function
The PHP sqrt() function is used to return the square root of the given number. It returns NAN for the square root of a negative number.
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 below example, sqrt() function is used to find out the square root of the given number.
<?php echo "The square root of 25 is: ".sqrt(25)."\n"; echo "The square root of 30 is: ".sqrt(30)."\n"; echo "The square root of 35.5 is: ".sqrt(35.5)."\n"; echo "The square root of -25 is: ".sqrt(-25)."\n"; ?>
The output of the above code will be:
The square root of 25 is: 5 The square root of 30 is: 5.4772255750517 The square root of 35.5 is: 5.9581876439065 The square root of -25 is: NAN
❮ PHP Math Functions