How can you use array_intersect() function to compare arrays in PHP?

To compare arrays in PHP, you can use the array_intersect() function which returns an array containing all the values that are present in all the input arrays. This function can be useful when you need to find common elements between two or more arrays. Simply pass the arrays you want to compare as arguments to the array_intersect() function and it will return an array with the common elements.

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

$common_elements = array_intersect($array1, $array2, $array3);

print_r($common_elements);