What are common pitfalls when using & in PHP code and how can they be avoided?

Common pitfalls when using & in PHP code include mistaking it for the logical AND operator instead of the bitwise AND operator, which can lead to unexpected results. To avoid this, always use && for logical AND operations and & for bitwise AND operations.

// Correct usage of logical AND operator
if ($a == 1 && $b == 2) {
    // Do something
}

// Correct usage of bitwise AND operator
$result = $a & $b;