为了账号安全,请及时绑定邮箱和手机立即绑定

如何检查数组对象值是否也存在于另一个对象数组值中?

如何检查数组对象值是否也存在于另一个对象数组值中?

PHP
守着星空守着你 2023-04-15 14:16:29
如何检查一个给定数组中任何对象的键值是否与另一个数组中任何对象的键值匹配?有两个数组,$personorg_terms和$org_terms_in_latest_post。name我想检查一个中的值是否存在于name另一个中。如果是这样,我们应该返回那个name。在下面的示例中,“S4 Capital”是一个匹配项,应该返回。$personorg_terms包含:Array(    [0] => WP_Term Object        (            [term_id] => 7436            [name] => WPP            [slug] => wpp            [term_group] => 0            [term_taxonomy_id] => 7436            [taxonomy] => company            [description] => WPP plc is a British multinational advertising and public relations company with its main management office in London, England, and its executive office in Dublin, Ireland.            [parent] => 0            [count] => 81            [filter] => raw            [term_order] => 0        )    [1] => WP_Term Object        (            [term_id] => 11814            [name] => S4 Capital            [slug] => s4-capital            [term_group] => 0            [term_taxonomy_id] => 11814            [taxonomy] => company            [description] => S4Capital is building a purely digital advertising and marketing services business for global, multi- national, regional, local and millennial-driven influencer brands.            [parent] => 0            [count] => 6            [filter] => raw            [term_order] => 0        ))$org_terms_in_latest_post包含:Array(    [0] => WP_Term Object        (            [term_id] => 11814            [name] => S4 Capital            [slug] => s4-capital            [term_group] => 0            [term_taxonomy_id] => 11814            [taxonomy] => company            [description] => S4Capital is building a purely digital advertising and marketing services business for global, multi- national, regional, local and millennial-driven influencer brands.            [parent] => 0            [count] => 6            [filter] => raw            [term_order] => 0        ))
查看完整描述

1 回答

?
叮当猫咪

TA贡献1776条经验 获得超12个赞

通过传递你的两个对象数组 $personorg_terms 和 $org_terms_in_latest_post 来试试这个


function getDuplicateObject($object_arr, $other_object_arr)

{

    $duplicates = array(); 

    foreach($object_arr as $ob1){


        foreach($other_object_arr as $ob2){

            if($ob1->name == $ob2->name)

                array_push($duplicates, $ob1->name); 

        }


    }

    return $duplicates;

}


查看完整回答
反对 回复 2023-04-15
  • 1 回答
  • 0 关注
  • 128 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信