⊗ppPmBsMOE 19 of 447 menu

Equal Precedence in PHP

Multiplication and division have equal precedence and are performed in order from left to right. Let's consider with an example what this means. In the following code, division will be performed first, and then multiplication:

<?php $a = 8 / 2 * 4; echo $a; // outputs 16 (result of 4 * 4) ?>

If you swap the operators, then multiplication will be performed first, and then division:

<?php $a = 8 * 2 / 4; echo $a; // outputs 4 (result of 16 / 4) ?>

In the following example, each new division operation will be applied to the previous one:

<?php $a = 16 / 2 / 2 / 2; echo $a; // outputs 2 ?>

Without running the code, determine what will be output to the screen:

<?php $a = 8 / 2 * 2; echo $a; ?>

Without running the code, determine what will be output to the screen:

<?php $a = 8 * 4 / 2 / 2; echo $a; ?>
byenru