Get two arrays diff in PHP using array_diff function

The array_diff function is very important to get difference of two arrays. It compares two arrays and return the values in the first array that are not present in the second array. This is particularly useful when you want to filter out elements or identify differences between two arrays. Example Example of array_diff mentioned below:


$arr1 = ['a', 'b', 'c', 'd'];
$arr2 = ['a', 'b'];
$result = array_diff($arr1, $arr2);
Output


// Output: Array ( [2] => c [3] => d )
print_r($result);