PHP sqrt()
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)
$valueis the number whose square root is being calculated.$resultis 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
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PHP on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours