In this tutorial, we are going to see how to compare two arrays and get the difference. You can use array_diff() function to compare an array to one or more other arrays. array_diff() function returns values from the first array that are not present in any of the other arrays.
How to compare two arrays and get the difference
<?php $arr1 = array("a", "b", "f", "g"); $arr2 = array("a", "b", "c", "d", "e"); // Compare values $cmp = array_diff($arr1, $arr2); print_r($cmp); ?>
Array (  => f  => g )