In this tutorial, you shall learn about Arithmetic Exponentiation Operator in PHP, its syntax, and how to use this operator in PHP programs, with examples.
PHP Exponentiation
PHP Arithmetic Exponentiation Operator takes two numbers as operands and returns the result of the first number raised to the power of second number.
Symbol
**
symbol is used for Exponentiation Operator.
Syntax
The syntax for Exponentiation Operator is
operand_1 ** operand_2
The operands could be of any numeric datatype, integer or float.
Examples
1. Integer raised to the Power (Exponent) of Integer
In the following example, we take integer values in $x
and $y
, and find $x
raised to the power $y
.
PHP Program
<?php
$x = 5;
$y = 4;
$output = $x ** $y;
echo "x = $x" . "<br>";
echo "y = $y" . "<br>";
echo "x ** y = $output";
?>
Output
2. Float value raised to the power of Integer
In the following example, we take floating point value in $x
and integer value $y
, and raise $x
to the power $y
.
PHP Program
<?php
$x = 3.14;
$y = 2;
$output = $x ** $y;
echo "x = $x" . "<br>";
echo "y = $y" . "<br>";
echo "x ** y = $output";
?>
Output
3. Float value raise to the power of Float value
In the following example, we take floating point values in $x
and in $y
, and find $x ** $y
.
PHP Program
<?php
$x = 3.14;
$y = 2.1;
$output = $x ** $y;
echo "x = $x" . "<br>";
echo "y = $y" . "<br>";
echo "x ** y = $output";
?>
Output
Conclusion
In this PHP Tutorial, we learned how to use Arithmetic Exponentiation Operator to raise a number to the power of another number.