What are the potential pitfalls of using modulus (%) operator in PHP to check for even numbers?

The potential pitfall of using the modulus (%) operator in PHP to check for even numbers is that it may not work correctly with negative numbers. This is because the modulus operator returns the remainder after division, which can be negative if the number being divided is negative. To solve this issue, you can use the abs() function to get the absolute value of the number before applying the modulus operator.

$num = -5;

if (abs($num) % 2 == 0) {
    echo "The number is even.";
} else {
    echo "The number is odd.";
}