array intersect for object array php

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

I want to know how to array_intersect for object array.

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-04 06:19

    nice toString function is already implemented and is called serialize ;) so

    array_map(
        'unserialize',
        array_intersect(
            array_map(
                'serialize',
                $obj1
            ), 
            array_map(
                'serialize', 
                $obj2
            )
        )
    );
    

    will do the work, example mentioned higher don't work 'cause array_intersect work's only with strings as someone mentioned too

提交回复
热议问题