What function can be used to remove elements present in one array but not in another in PHP?

To remove elements present in one array but not in another in PHP, you can use the array_diff() function. This function takes two arrays as arguments and returns an array containing all the values from the first array that are not present in any of the other arrays.

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

$diff = array_diff($array1, $array2);

print_r($diff);