How can casting be used to prevent unexpected results when comparing integers and strings in PHP?

When comparing integers and strings in PHP, unexpected results can occur due to PHP's loose typing system. To prevent this, you can use casting to explicitly convert the variables to the same type before comparing them. For example, you can cast the string to an integer using `(int)` or the integer to a string using `(string)` before performing the comparison.

$integer = 10;
$string = "10";

// Casting the string to an integer before comparison
if ($integer === (int)$string) {
    echo "The integer and string are equal.";
} else {
    echo "The integer and string are not equal.";
}