PHP nested array loops with array update
<p>I'm from a VB; Access; SQL Server background recently introduced to WAMP. I have a problem which I have not been able to solve for a few weeks now, I think I have visited every forum on the web (including here) without success.</p>

<p>I have two arrays filled from MySQL recordsets, one for the site Cart and the other for one of the site departments (catalogs) see a manual interpretation of the filled arrays below.</p>

<pre><code>$catalog[] = array( 
  array('ProdID'=&gt;2,'Name'=&gt;'Alpha','DepID' =&gt;2,'InBasket'=&gt;'0'),       
  array('ProdID'=&gt;6,'Name'=&gt;'Alpha','DepID' =&gt;2,'InBasket'=&gt;'0'),
  array('ProdID'=&gt;7,'Name'=&gt;'Alpha','DepID' =&gt;2,'InBasket'=&gt;'0'),
  array('ProdID'=&gt;8,'Name'=&gt;'Alpha','DepID' =&gt;2,'InBasket'=&gt;'0'),
  array('ProdID'=&gt;9,'Name'=&gt;'Alpha','DepID' =&gt;2,'InBasket'=&gt;'0'),
);


$cart[] = array(
  array('Name'=&gt;'Alpha2','Loc'=&gt;'e_vol1','BasketID'=&gt;'81','ProdID'=&gt;'2','Quant'=&gt;'1'),
  array('Name'=&gt;'Beta4','Loc'=&gt;'e_vol2','BasketID'=&gt;'81','ProdID'=&gt;'4','Quant'=&gt;'1'),
  array('Name'=&gt;'Alpha8','Loc'=&gt;'e_vol3','BasketID'=&gt;'81','ProdID'=&gt;'8','Quant'=&gt;'1'),
  array('Name'=&gt;'Gamma21','Loc'=&gt;'e_vol4','BasketID'=&gt;'81','ProdID'=&gt;'21','Quant'=&gt;'1'),
);
</code></pre>

<p>What I need to do is loop through the catalog array each time a new catalog is chosen, comparing the ProdID of each row in the cart against the ProdID of each row of the catalog, when a match is found I would like to update the catalog 'InBasket' value for that row only to '1' to indicate that the item is already in the customers cart which I can then show on screen (The customer is only allowed to purchase one of any item).</p>

<p>There are five different departments (catalogs) which will contain up to 10 products the cart will contain say four items (If I'm lucky)</p>

<p>I have tried some loops but they don't seem to work.</p>

<pre><code>for ($x = 0; $x &lt; count($catalog); $x++)
{
  for ($y = 0; $y &lt; count($cart); $y++)
  {
    If ($catalog[$x]['ProductID'] == $cart[$y]['ProductID'] )
    {
      $cart[$x]['InBasket'] = 1;
    }
  }
}
</code></pre>

<p>I hpoe that my arrays are correct, but, the loops seem to update 'InBasket' regardless.</p>

<p>Any ideas would be appreciated.</p>
