I want to know how to array_intersect for object array.
|
nice toString function is already implemented and is called serialize ;) so
will do the work, example mentioned higher don't work 'cause array_intersect work's only with strings as someone mentioned too |
|||||||||
|
Then what mean present in this context (exacly this function), i found on php.net my answer: Then you can't use it on array of objects if your objects not implements unique conversion to string. |
|||||||||||||
|
The correct way to check whether two objects are equal is to use
|
|||||||||
|
Had a similar problem a few days ago, while these are answers are on the right path; I used them to work out the following: From Artefacto's answer
Then it’s jut a matter of calling array_uintersect with our comparative function to get the intersection:
In my case, I had an unknown / dynamic array of objects, so I took it a step further so I don't have to declare
Just gotta remember to pass in the reference to our callback / comparative function as the last string in the array. Works like a charm! |
|||||
|