PHP sqrt() Function

In this chapter you will learn:

  1. Definition for PHP sqrt() Function
  2. Syntax for PHP sqrt() Function
  3. Parameter for PHP sqrt() Function
  4. Return for PHP sqrt() Function
  5. Example - Return the square root of different numbers

Definition

The sqrt() function gets the square root of a number.

Syntax

PHP sqrt() Function has the following syntax.

float sqrt ( float num )

Parameter

ParameterDescription
numberRequired. Specifies a number

Return

Item Value
Return ValueThe square root of number, or NAN for negative numbers
Return TypeFloat

Example

Return the square root of different numbers:


<?php//  j a  va 2s.c  om
print sqrt(25); 
print "\n";
print sqrt(26); 
print "\n";
echo(sqrt(0) . "\n");
echo(sqrt(1) . "\n");
echo(sqrt(9) . "\n");
echo(sqrt(0.64) . "\n");
echo(sqrt(-9));
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP srand() Function
  2. Syntax for PHP srand() Function
  3. Parameter for PHP srand() Function
  4. Return for PHP srand() Function
  5. Example - Seed the random number generator