PHP Operators Association

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Left association

If the preceedence of two operators is equal, the associativity determines the grouping (see also the Remarks section):

$a = 5 * 3 % 2; // $a now is (5 * 3) % 2 => (15 % 2) => 1

* and % have equal precedence and left associativity. Because the multiplication occurs first (left), it is grouped.

$a = 5 % 3 * 2; // $a now is (5 % 3) * 2 => (2 * 2) => 4

Now, the modulus operator occurs first (left) and is thus grouped.

Right association

$a = 1;
$b = 1;
$a = $b += 1;

Both $a and $b now have value 2 because $b += 1 is grouped and then the result ($b is 2) is assigned to $a.



Got any PHP Question?