How can you properly compare values in PHP to avoid assignment instead of comparison?

When comparing values in PHP, it's important to use the triple equals operator (===) instead of the double equals operator (==) to avoid unintentional type coercion and assignment instead of comparison. The triple equals operator checks both the value and the type of the operands, ensuring a more accurate comparison.

// Incorrect comparison using double equals operator
$value1 = "10";
$value2 = 10;

if ($value1 == $value2) {
    echo "Values are equal.";
} else {
    echo "Values are not equal.";
}

// Correct comparison using triple equals operator
if ($value1 === $value2) {
    echo "Values are equal.";
} else {
    echo "Values are not equal.";
}