sqrt()

ArvindNexus's avatar
Published Aug 11, 2023
Contribute to Docs

The sqrt() function calculates the square root of a number. It takes a single parameter in the form of a number and returns the square root of that number.

Syntax

$result = sqrt($value)
  • $value is the number whose square root is being calculated.
  • $result is the resultant square root value.

Note: If a negative number is passed as an argument, the function will return NAN. Therefore, only nonnegative numbers should be passed to avoid unexpected results and maintain accurate calculations.

Example

The following example demonstrates the usage of sqrt() function to find the square root of $value.

<?php
$value = 25;
$squareRoot = sqrt($value);
echo "The square root of $value is: $squareRoot";
?>

The example will result in the following output:

The square root of 25 is: 5

All contributors

Contribute to Docs

Learn PHP on Codecademy