PHP sqrt() Function
Syntax
sqrt($number);
Parameter | Description |
Number | Number can be integer or float |
Definition
It Returns the square root of the any number.
Usage
Sqrt function is used to calculate the square root of number, number can be integer of float.
Example of sqrt function
<?php echo sqrt(16); ?>
- Example
- Run
In above example 16 is an integer type number that has passed into the sqrt function as an argument and it will calculate the square root of the number 16.
More example of sqrt function
<?php $a = 144; var_dump($a); echo sqrt($a); ?>
- Example
- Run
In above example $a is a variable that has held integer value as previous example but in this case first it has to stored on a variable and then passed it to the sqrt function.
You can check data type of any variable or value by using var_dump function as i used. And at last the variable $a has passed into the sqrt function.
Example
<form method="post"> Enter any number <br/> <input type="text" name="uk"><br/> <input type="submit" name="sub"> </form> <?php if(isset($_POST['sub'])) { $uk=$_POST['uk']; echo "Result = " . sqrt($uk); } ?>
Output
You can enter any number integer as well as float for calculating square root.