What are the potential pitfalls of using modulo (%) operator for checking even numbers in PHP?

Using the modulo (%) operator to check for even numbers in PHP can lead to potential pitfalls because it may not work correctly with negative numbers. To solve this issue, it is recommended to use the bitwise AND (&) operator with 1 instead. This will ensure that the check works correctly for both positive and negative numbers.

function isEven($num) {
    return ($num & 1) == 0;
}

// Example usage
$num = 10;
if (isEven($num)) {
    echo "$num is even";
} else {
    echo "$num is odd";
}