In what scenarios would the use of array_intersect be more suitable than array_diff when comparing arrays in PHP?

When comparing arrays in PHP, array_intersect is more suitable than array_diff when you want to find the common elements between two arrays. This function will return an array containing values that are present in both arrays. On the other hand, array_diff will return an array containing values that are present in the first array but not in the second array.

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

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

print_r($common_elements);