array intersect for object array php

前端 未结 8 1486
独厮守ぢ
独厮守ぢ 2021-01-04 05:55

I want to know how to array_intersect for object array.

8条回答
  •  醉梦人生
    2021-01-04 06:13

    You can use array_uintersect in conjunction with spl_object_hash, see an example:

        array_uintersect($a, $b, function($a, $b) {
            return strcmp(spl_object_hash($a), spl_object_hash($b));
        });
    

    where '$a' and '$b' are arrays of some objects that you want to intersect.

提交回复
热议问题