亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何檢查數組對象值是否也存在于另一個對象數組值中?

如何檢查數組對象值是否也存在于另一個對象數組值中?

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 關注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號