PHP sqrt() Function

Definition and Usage

The sqrt() function returns square root of a positive float number. Since square root for negative number is not defined, it returns NAN. This is one of the most commonly used functions.

This function always returns a floating point number.

Syntax

sqrt ( float $arg ) : float

Parameters

Sr.No Parameter & Description
1 arg
a number whose square root is to be obtained

Return Values

PHP sqrt() function returns square root of the given arg number. For negative number, the function returns NAN.

PHP Version

This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.

Example

<?php
   echo "sqrt(-1) = " . sqrt(-1) . "
"; ?>

Output

This will produce following result −

sqrt(-1) = NAN
Updated on: 2026-03-11T23:22:53+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements