how to remove a particular key => value from a session array?
<p>let's say i have $_SESSION['cart']; when I print this</p>

<pre><code>echo "&lt;pre&gt;",print_r($_SESSION['cart']),"&lt;/pre&gt;"; 
</code></pre>

<p>it will show something like</p>

<pre><code>Array
(
    [1] =&gt; 2
    [2] =&gt; 2
)
</code></pre>

<p>where the keys are the product IDs and the value is the quantity of each product.
so, if I would want to delete product no. 2  from that session array, 
how am to do that ?</p>

<p>I tried the fastest function that came to my mind</p>

<pre><code> public function removeItem($id2){
   foreach($_SESSION['cart'] as $id =&gt; $qty) {
        if ($id == $id2){
         unset($_SESSION['cart'][$id]);

      }
   }
 }
</code></pre>

<p>it deleted the whole $_SESSION['cart'] data :(</p>
