appending to multidimensional arrays in PHP
<p>I am trying to use session variables in an e-commerce website. The idea is to start a session if one is not started already. If there's already a session, then i want to check if the new item that was added already exists in the session array. If so, then i'd just increase the quantity, if not then append to the current session array.</p>

<p>Problem is that appending does not work. I get the first and second arrays, but instead of adding a third the second array keeps getting overwritten anytime the add to cart button is clicked. Here is my code</p>

<pre><code>&lt;?php 

                if(isset($_SESSION['cart'])){
                    $newItems = '';
                    $cart = $_SESSION['cart'];
                    foreach($cart as $item =&gt; $value){
//$size, $colour, $quantity and $price are the current $_GET values
                        if($prodId == $value['prodId'] &amp;&amp; $value['colour'] == $colour &amp;&amp; $value['size'] == $size &amp;&amp; $value['price'] == $price){
                            $value['qty']+= $quantity;
                            }else{
                                $newItems = array('prodId'=&gt;$prodId,'price'=&gt;$price,'qty'=&gt;$quantity,'colour'=&gt;$colour,'size'=&gt;$size);
                                $cart []= $newItems;
                                }
                        }
                    }else{
                        $_SESSION['cart'] []= array('prodId'=&gt;$prodId,'price'=&gt;$price,'qty'=&gt;$quantity,'colour'=&gt;$colour,'size'=&gt;$size);
                        }

?&gt;
</code></pre>

<p>Really don't know where it went wrong, i've such rotten luck with multidimensional arrays. Any help will be most appreciated.</p>
