How can the trim() function in PHP be utilized to handle whitespace issues when checking for duplicate values?

When checking for duplicate values, whitespace can cause issues as it may result in false negatives. To handle this, the trim() function in PHP can be used to remove any leading or trailing whitespace from the input values before comparing them. This ensures that whitespace differences do not affect the comparison results.

$value1 = "  example ";
$value2 = "example";

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