CKTIS / PHP
Exponentiation with assignment (**=)
Replace a variable by a power of its current value.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
$value **= $operandReplace a variable by a power of its current value. Squaring twice gives the fourth power of the original value.
The left operand is the base and the right operand is the exponent. A negative exponent can yield a fraction even for an integer base. Parentheses determine whether a minus sign belongs to the base.
Evaluation
$value = 2; $value **= 5;→32$value = 2; $value **= (-2);→0.25$value = 9; $value **= 0;→1
Examples
<?php
$value = 2;
$value **= 5;
echo json_encode($value), PHP_EOL;
$value = 2;
$value **= (-2);
echo json_encode($value), PHP_EOL;
$value = 9;
$value **= 0;
echo json_encode($value), PHP_EOL;
Result
32 0.25 1