Exponentiation Precedence in PHP
The exponentiation operation has precedence over multiplication and division. In the following example, exponentiation will be performed first, and then multiplication:
<?php
echo 2 * 2 ** 3;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$a = 3 * 2 ** 3;
echo $a;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$a = (3 * 2) ** 3;
echo $a;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$a = 3 * 2 ** (3 + 1);
echo $a;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$a = 2 ** 3 * 3;
echo $a;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$a = 3 * 2 ** 3 * 3;
echo $a;
?>