What Does ** Do in PHP?

In PHP, "**" represents the exponentiation operator, which returns the result of raising the first operand to the power of the second operand.

For example, the mathematical expression 2 ^ 5 (i.e. two raised to the power of five) can be expressed using the exponentiation operator in the following way:

var_dump(2 ** 5); // 32

In this case, 2 is the base and 5 is the exponent.

This is the same as using the pow() function:

var_dump(pow(2, 5)); // 32

Using either, the exponential operator (**) or the pow() function, is merely a shorter form of multiplying the base number as many times to itself as denoted by the exponent. For example, consider the following, which is equivalent to the examples above:

var_dump(2 * 2 * 2 * 2 * 2); // 32

Hope you found this post useful. It was published . Please show your love and support by sharing this post.