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:


Operators:
* Association

Table Of Contents
2 Arrays
4 Types
10 Cookies
14 JSON
15 SOAP
17 cURL
19 XML
21 Traits
33 Operators
35 UTF-8
36 URLs
38 PHPDoc
41 Loops
44 Closur
72 YAML
77 Cache
78 Streams
81 PDO
82 SQLite3
83 Sockets
87 MongoDB
93 IMAP
94 Redis
95 Imagick
102 APCu
108 PSR