php compare two arrays of objects

Solutions on MaxInterview for php compare two arrays of objects by the best coders in the world

showing results for - "php compare two arrays of objects"
Jayden
22 Aug 2018
1// 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.
2
3function compare_objects($obj_a, $obj_b) {
4  return $obj_a->id - $obj_b->id;
5}
6
7$diff = array_udiff($first_array, $second_array, 'compare_objects');
8