PHP give us an operator for raising a number to the power of another number: the exponentiation operator (
For example, we can square a number by raising it to the power of 2:
echo 4 ** 2; // Prints: 16
We can also use this operator on floats and negative numbers:
echo 2.89 ** 3.2; // Prints: 29.845104015297 echo 10 ** -1; // Prints: 0.1
For PHP to interpret this operator correctly it can’t have any spaces between the two
echo 2 * * 3; // Will result in an error
Let’s do some more math!
echo and the exponent operator to print the value of 8 squared to the terminal.