How to use Exponentiation Operator (**) In PHP
The exponential operator (**) is used to calculate the exponent power of number. Here, we use exponent power to 0.5.
Syntax:
$number ** 0.5;
Example:
PHP
<?php function squareRoot( $number ) { return $number ** 0.5; } $num = 36; echo "Square Root: " . squareRoot( $num ); ?> |
Output
Square Root: 6
PHP Program to Find Square Root of a Number
Given a Number, the task is to find the Square Root of Number in PHP.
Examples:
Input: 15
Output: 5
Input: 30
Output: 5.477
There are three methods to find the square root of the given number, these are:
Table of Content
- Using sqrt() Function
- Using pow() Function
- Using Exponentiation Operator (**)