Calculating the Difference Between Two Arrays in PHP


Use array_diff() to find elements present in one array but not in others.

Source Code

$array1 = ['a', 'b', 'c', 'd'];
$array2 = ['b', 'd'];
$difference = array_diff($array1, $array2);
print_r($difference); // Outputs: Array ( [0] => a [2] => c )
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments