I know there is array_diff and array_udiff for comparing the difference between two arrays, but how would I do it with two arrays of objects?
array(4) {
[0]=>
object(stdClass)#32 (9) {
["id"]=>
string(3) "205"
["day_id"]=>
string(2) "12"
}
}
My arrays are like this one, I am interested to see the difference of two arrays based on id column values.
This is exactly what
array_udiffis for. Write a function that compares two objects the way you would like, then tellarray_udiffto use that function. Something like this:Or, if you’re using PHP >= 5.3 you can just use an anonymous function instead of declaring a function: