title: how to unset a specific key value from a session array in php
body: <p>I have a booking cart for booking for products and at some point, user would be able to delete specific products from their cart.</p>
  
  <p>I need help deleting product from the session array cos I keep getting an error message "Fatal error: Cannot unset string offsets" while trying to delete a product.</p>
  
  <p>Here is the code for deleting</p>
  
  <pre><code>    &lt;?php
  
  if(isset($_GET['inh_arr_key']) &amp;&amp; isset($_GET['c_id'])) {
  
  $inh_arr_key = $_GET['inh_arr_key'];
  $del_c_id = $_GET['c_id'];
  
  unset($_SESSION['inh_cart'][$inh_arr_key]);
  
  
  $inh_cart = $_SESSION['inh_cart'];
  
  // Parse the cart session variable
  $inh_arr = explode(',',$inh_cart);  
  
  if (array_key_exists($inh_arr_key, $inh_arr)) {
      echo '&lt;p class="err_msg"&gt;Unable to delete selected course from your In-house course booking cart.&lt;/p&gt;';
  }
  else{
  
  $del_inh_query_course_info = @mysql_query("select * from inhouse_prod where id='".$del_c_id."'");
  $del_inh_course_det = @mysql_fetch_assoc($del_inh_query_course_info);   
  $del_inh_course_title = $del_inh_course_det['title'];
  
      echo '&lt;p class="ok_msg"&gt;&lt;strong&gt;'.$ex_inh_course_title.'&lt;/strong&gt; has been deleted from your In-house course booking cart.&lt;/p&gt;';    
  }
  
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <p>I've fetched and appended each products array key and value to them. So that's being retrieved by $_GET and they are in these variables</p>
  
  <pre><code>$inh_arr_key = $_GET['inh_arr_key'];
  $del_c_id = $_GET['c_id'];
  </code></pre>
  
  <p>Just to provide more detail about the question, here is the code for adding products to the cart and it's working fine</p>
  
  <pre><code>&lt;?php
  
  
  
  $c_id = $_GET['c_id'];
  
  session_name("inh_cart");
  
  session_start();
  
  $inh_cart = $_SESSION['inh_cart'];
  if ($inh_cart) {
  
  $get_inh_arr = explode(',',$inh_cart);
  
  if(in_array($c_id, $get_inh_arr)){ 
  $inh_cart = $inh_cart;
  
  ?&gt;
      &lt;script language="javascript"&gt;
      window.location = "user_allc_booking.php?ex_inh_cid=&lt;?php echo $c_id; ?&gt;";
      &lt;/script&gt;
  &lt;?php
  
  }
  else {
  $inh_cart .= ','.$c_id;
  }
  
  
  } else {
  $inh_cart = $c_id;
  }
  $_SESSION['inh_cart'] = $inh_cart;
  
  
  ?&gt;
      &lt;script language="javascript"&gt;
      window.location = "user_allc_booking.php";
      &lt;/script&gt;
  &lt;?php
  
  
  
  $inh_query_course_info = @mysql_query("select * from inhouse_courses where id='".$c_id."'");
  $inh_course_det = array();
  $inh_course_det = @mysql_fetch_assoc($inh_query_course_info);   
  $inh_course_title = $inh_course_det['title'];
  
  
  
  
  ?&gt;
  </code></pre>
  
  <p>And if for example the cart contain 3 product, if I do a var_dump($_SESSION['inh_cart']);</p>
  
  <p>The output will be:</p>
  
  <pre><code>string(8) "20,48,24"
  </code></pre>
  
  <p>Really need to what's wrong with the codes for deleting products. Need help with this. Thanks!</p>