The sqrt()
function in PHP returns the square root of a non-negative number.
Figure 1 below shows the mathematical representation of the sqrt()
function.
float sqrt(number)
sqrt()
requires a non-negative number as a parameter. If the number is negative, then this function returns NaN
.
sqrt()
returns the square root of the number sent as a parameter.
The following example shows how to use the sqrt()
function in PHP.
<?phpecho("sqrt(4): ");echo (sqrt(4));echo("\n");echo("sqrt(0): ");echo (sqrt(0));echo("\n");echo("sqrt(25): ");echo (sqrt(25));echo("\n");echo("sqrt(4.5): ");echo (sqrt(4.5));echo("\n");#error outputecho("sqrt(-4): ");echo (sqrt(-4));?>