What PHP function can be used to compare two arrays and find the common values?

To compare two arrays and find the common values, you can use the array_intersect() function in PHP. This function takes two or more arrays as arguments and returns an array containing the values that are present in all of the input arrays. This allows you to easily identify the common values between two arrays.

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

$commonValues = array_intersect($array1, $array2);

print_r($commonValues);