How can the explode function in PHP be utilized to extract specific values from a string for comparison purposes?

When we have a string containing multiple values separated by a delimiter, we can use the explode function in PHP to split the string into an array of substrings based on the delimiter. We can then access specific values from the array for comparison purposes. By specifying the delimiter and index of the desired value, we can easily extract and compare specific values from the original string.

$string = "apple,orange,banana,grape";
$values = explode(",", $string);

// Extracting specific values for comparison
$firstValue = $values[0];
$secondValue = $values[1];

// Comparing extracted values
if ($firstValue == "apple") {
    echo "First value is apple";
}

if ($secondValue == "orange") {
    echo "Second value is orange";
}