Compare two arrays save data to matches
<p>I have two arrays I need to compare....</p>

<p>$Drink Array</p>

<pre><code>(
[0] =&gt; Drink Object
    (
        [top_id] =&gt; 40C6-88
        [name] =&gt; Pepsi
        [drink_id] =&gt; E936
    )

[1] =&gt; Drink Object
    (
        [top_id] =&gt; 46DB-9E
        [name] =&gt; Orange Juice
        [drink_id] =&gt; E936
    )
)

[2] =&gt; Drink Object
    (
        [top_id] =&gt; 5J71-4F79
        [name] =&gt; Dr Pepper     
        [drink_id] =&gt; E936
    )
</code></pre>

<p>$DrinkItem Array</p>

<pre><code>(
[0] =&gt; DrinkItem Object
    (
        [bottom_id] =&gt; 45BD-92DD
        [name] =&gt; Diet Coke      
        [drink_template_id] =&gt; 3B2A-4D82
    )

[1] =&gt; DrinkItem Object
    (
        [bottom_id] =&gt; 4A71-8F79
        [name] =&gt; Orange Juice     
        [drink_template_id] =&gt; 3B2A-4D82
    )


)
</code></pre>

<p>.. If the name matches one of the names in the DrinkItem Array I need to store the top_id of that item.</p>

<p>I was trying to do something like:</p>

<pre><code>foreach ($Drink as $d) {
    foreach ($DrinkItem as $item){
        if ($d-&gt;name == $item-&gt;name){
            $match = $d-&gt;top_id;
        }
    }
}
</code></pre>

<p>But I might be way off base here. If there's a better approach for storing the id of the matches, or if i'm on the right track, any help is very appreciated!</p>
