Grouping Parentheses in PHP
If desired, you can specify the priority of operations using parentheses. Let's, for example, modify our code so that the addition is performed first, and then the multiplication:
<?php
$a = 2 * (2 + 3);
echo $a; // outputs 10 (result of 2 * 5)
?>
There can be any number of parentheses, including ones nested within each other:
<?php
$a = 2 * (2 + 4 * (3 + 1));
echo $a;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$a = (2 + 3) * (2 + 3);
echo $a;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$a = (2 + 3) * 2 + 3;
echo $a;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$a = 2 * (2 + 4 * (3 + 1));
echo $a;
?>
Without running the code, determine what will be displayed on the screen:
<?php
$a = 2 * 8 / 4;
echo $a;
?>