php - How to check if array object value also exists in another object array value?
Get the solution ↓↓↓How do I check whether the key value of any object within one given array matches the key value of any object within another array?
There are two arrays,$personorg_terms
and$org_terms_in_latest_post
.
I want to check whether the value ofname
in one exists in thename
of another. If so, we should return thatname
.
In the below example, "S4 Capital" is a match and should be returned.
$personorg_terms
contains:
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
contains:
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
)
)
Answer
Solution:
Try this by passing your two object arrays $personorg_terms and $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;
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non well formed numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.