What are some common pitfalls when using array_diff in PHP?

One common pitfall when using array_diff in PHP is that it only compares values and not keys. If you want to compare both keys and values, you can use the array_diff_assoc function instead. Another pitfall is that array_diff is case-sensitive, so make sure the values you are comparing are in the same case. Additionally, array_diff only works with one-dimensional arrays, so if you have multidimensional arrays, you may need to flatten them before using array_diff.

// Using array_diff_assoc to compare both keys and values
$array1 = ['a' => 1, 'b' => 2, 'c' => 3];
$array2 = ['a' => 1, 'b' => 2];
$diff = array_diff_assoc($array1, $array2);
print_r($diff);