How can the in_array() function be used to compare values in two arrays and remove specific elements in PHP?

To compare values in two arrays and remove specific elements in PHP, you can use the `in_array()` function to check if a value exists in the second array, and then remove that value from the first array if it does. This can be achieved by iterating through the first array and using `in_array()` to check each value against the second array. If a match is found, the value can be removed using `unset()`.

$array1 = [1, 2, 3, 4, 5];
$array2 = [2, 4];

foreach ($array1 as $key => $value) {
    if (in_array($value, $array2)) {
        unset($array1[$key]);
    }
}

print_r($array1);