What is the significance of operator precedence and associativity when working with bitwise operations in PHP?

Operator precedence and associativity are important when working with bitwise operations in PHP because they determine the order in which operators are evaluated. This can impact the outcome of bitwise operations if not used correctly. To ensure the desired outcome, it is important to understand the precedence and associativity rules for bitwise operators in PHP.

// Example of using parentheses to control operator precedence in bitwise operations
$a = 5;
$b = 3;
$c = 2;

$result1 = ($a & $b) | $c; // Ensures that the bitwise AND operation is performed before the bitwise OR operation
echo $result1; // Output: 3

$result2 = $a & ($b | $c); // Ensures that the bitwise OR operation is performed before the bitwise AND operation
echo $result2; // Output: 5