如何檢查一個給定數組中任何對象的鍵值是否與另一個數組中任何對象的鍵值匹配?有兩個數組,$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;
}
- 1 回答
- 0 關注
- 157 瀏覽
添加回答
舉報
0/150
提交
取消