Answers for "php compare 2 arrays for matches"

PHP
3

compare two arrays and return the difference php

array_merge(array_diff($array1,$array2),array_diff($array2,$array1))
Posted by: Guest on March-11-2021
0

php compare two arrays of objects

// Computes the difference of arrays by using a callback function for data comparison. This is unlike array_diff() which uses an internal function for comparing the data.

function compare_objects($obj_a, $obj_b) {
  return $obj_a->id - $obj_b->id;
}

$diff = array_udiff($first_array, $second_array, 'compare_objects');
Posted by: Guest on August-16-2021

Code answers related to "php compare 2 arrays for matches"

Browse Popular Code Answers by Language