array intersect for object array php

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

I want to know how to array_intersect for object array.

8条回答
  •  情歌与酒
    2021-01-04 06:12

    The correct solution would be:

    array_uintersect($arr1, $arr2, function ($a1, $a2) { return $a1 != $a2; });
    

    Note the != in the callback function as opposed to the answer from @Artefacto. Based on the documentation of array_uintersect, the callback function has to return 0 (false) if array items are equal.

提交回复
热议问题