Association

suggest change

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents