title: Remove item from session onClick
body: <p>I'm trying to remove an item from a sort of shopping cart. The items are saved to a session when they are "saved to the shopping cart".</p>
  
  <p>But now I would like to be able to remove certain items from this "shopping cart". Because I got the script from here (stackoverflow) I'm not that familiar with the code. I saw some answers on google and here that described using <code>unset</code> to delete the entry from the session. But I wouldn't know where to start with this one. If additional information is needed please let me know. Thanks for having a look at my question... </p>
  
  <p>Here is the HTML (nothing special):</p>
  
  <pre><code>&lt;div class="txtHint"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>This is my script:</p>
  
  <pre><code>$('.add-product').click(function() {
          var productName = $(this).data('product');
              $.post('example.com/reload.php', {productName: productName}, function(data) {
              $('.txtHint').html(data);
          })
      });
  </code></pre>
  
  <p>This is my reload.php file:</p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  if (!array_key_exists('products', $_SESSION) || !is_array($_SESSION['products'])) {
      $_SESSION['products'] = [];
  }
  
  $productName = array_key_exists('productName', $_POST) ? (string) $_POST['productName'] : '';
  
  if ($productName) {
      $_SESSION['products'][] = $productName;
  }
  ?&gt;
  
  &lt;h4&gt;Saved Items&lt;/h4&gt;
    &lt;?php foreach ($_SESSION['products'] as $product): ?&gt;
      &lt;div class="echo-product"&gt;&lt;i style="color:#F60;padding-right:20px;" class="fa fa-anchor" aria-hidden="true"&gt;&lt;/i&gt;&lt;?php echo htmlspecialchars($product); ?&gt;&lt;/div&gt;
      &lt;?php endforeach;?&gt;
  </code></pre>
  
  <p>Updated code: As suggested by Bert Maurau (I Hope).</p>
  
  <pre><code>&lt;?php
  
  session_start();
  
  if (!array_key_exists('products', $_SESSION) || !is_array($_SESSION['products'])) {
      $_SESSION['products'] = [];
  }
  
  $productName = array_key_exists('productName', $_POST) ? (string) $_POST['productName'] : '';
  
  if(isset($_GET['delparam'])){
     unset($_SESSION['products'][$productName]);
  }
  if(isset($_GET['addparam'])){
      $_SESSION['products'][] = $productName;
  }
  ?&gt;
  </code></pre>
  
  <p>If I use this it doesn't add any new items... </p>