How to check if the same value exists in two arrays with php
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/11789897/how-check-any-value-of-array-exist-in-another-array-php">How check any value of array exist in another array php?</a>  </p>
</blockquote>



<p>I am creating a shopping site. To simplify, I have 2 arrays, one holds all my items and the other holds all the items that are added on the cart :</p>

<p><strong>$Items</strong></p>

<pre><code>Array
(
    [0] =&gt; stdClass Object
        (
            [id] =&gt; 1
            [title] =&gt; Verity soap caddy
            [price] =&gt; 6.00
        )

    [1] =&gt; stdClass Object
        (
            [id] =&gt; 2
            [title] =&gt; Kier 30cm towel rail
            [price] =&gt; 14.00
        )
      //a lot more
)
</code></pre>

<p><strong>$cartItems</strong></p>

<pre><code>Array
(
    [0] =&gt; Array
        (
            [rowid] =&gt; c4ca4238a0b923820dcc509a6f75849b
            [id] =&gt; 1
            [qty] =&gt; 1
            [price] =&gt; 6.00
            [name] =&gt; Verity soap caddy
            [subtotal] =&gt; 6
        )
)
</code></pre>

<p>I would like to loop through the <strong>$cartItems</strong> and add a class (identify) if an item is also in the cart. This is how I tried to do it </p>

<pre><code>foreach($items as $items){
  if($cartItems[$items-&gt;id]['id']){
    echo '&lt;h1 class="inCart"&gt;'. $item-&gt;title . '&lt;/h1&gt;' //...
   }else{
    echo '&lt;h1&gt;'. $item-&gt;title . '&lt;/h1&gt;' //...
   }
}
</code></pre>

<p>The above code does not work - even though <code>$cartItems[0]['id']</code> would return what I need. My thinking is, whilst looping through $items, check if the similar id exists in the <code>$cartItems</code> array. I also tried to add <code>$cartItems[$i]['id']</code> and increment <code>$i</code> within the loop, and that did not work.
Of course the html output that I wanted to get is (simplified) </p>

<pre><code>&lt;h1 class="IsOnCart"&gt; Item Title&lt;/h1&gt;
&lt;h1&gt; Item Title&lt;/h1&gt;
&lt;h1 class="IsOnCart"&gt; Item Title&lt;/h1&gt;
&lt;h1&gt; Item Title&lt;/h1&gt;
</code></pre>

<p>Is there a way to implement this?
Thanks </p>
