title: PHP cannot extract array values by index
body: <p>Ok So I'm making a shop at the moment, to store the shopping cart I'm using arrays of $basketItems, $basketWeights and $basketQuantities. Each index will relate to an item in the basket.</p>
  
  <p>My code works by looping round each of the items in the basket (according to the arrays I have) then pulling the relevant information from the database.</p>
  
  <p>The code works great for the first row it pulls from the database however this fails as soon as it reaches the second item, yet I have no idea why.</p>
  
  <p>The problem seems to occur with not being able to get the required value at correct index from the $weights or $prices arrays. You'll notice in the code, to check whether or not the array $weights is forming correctly I have echo'd it, also echo'd the index I want to retrieve, which looks ok, the only problem is that it doesn't echo anything (as far as I can tell!)</p>
  
  <p>The code is as follows</p>
  
  <pre><code>    &lt;?
  /*
  $basketItems
  $basketWeights
  $basketProducts
  
  are arrays, each value stores the index of the item relating to the product in the database */
  
  //show basket, go through all the basket items, the retrieves relevant information from the database
  for($index = 0; $index &lt; sizeof($basketItems); $index++)
  {
      //get product at this index
      $getProduct = mysql_query("SELECT * from shop_products where prid='".$basketItems[$index]."' limit 1") or die(mysql_error());
      $product = mysql_fetch_array($getProduct);
      //weights is an array for each product ie 100, 200, 500
      $weights = explode(",", $product['prweights']);
      $weightIndex = $basketWeights[$index];
      $prices = explode(",", $product['prprices']);
  ?&gt; &lt;tr&gt;
  &lt;td&gt;&lt;b&gt;&lt;? print_r(array_values($weights)); ?&gt;&lt;/b&gt;&lt;/td&gt;
  &lt;/tr&gt;&lt;tr&gt;
      &lt;td&gt;&lt;? echo($product['prtitle']); ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;? echo ("$weightIndex/$weights[$weightIndex]"); ?&gt;g&lt;/td&gt;
      &lt;td&gt;&lt;? echo($basketQuantities[$index]); ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;? echo $prices[$weightIndex]; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;? echo ($prices[$weightIndex] * $basketQuantities[$index]); ?&gt;&lt;/td&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?
  
    }
  ?&gt;
  </code></pre>
  
  <p>And the result can be seen here:
  <a href="http://www.jamesmoorhouse.co.uk/images/shop.png" rel="nofollow">http://www.jamesmoorhouse.co.uk/images/shop.png</a></p>
  
  <p>As you can see from the screenshot, it just doesn't echo anything where it should echo the result from the array seen above each product.</p>
  
  <p>The format of testing for the 2nd column is arrayIndex/arrayValueAtIndex g</p>