How can I delete session? I create $_SESSION['loop'][$id].
When I unset $id = 0 then all of $_SESSION['loop'] are delete.
How can I do this?

$id = \Drupal::request()-&gt;query-&gt;get('id');

if (isset($_SESSION['loop']) &amp; (isset($id)) &amp; ( $_SESSION['loop'] &gt; 0)) {
  $_SESSION['loop'] = $_SESSION['loop'] - 1;
  unset($_SESSION['label'][$id]);
  unset($_SESSION['code'][$id]);
  unset($_SESSION['price'][$id]);
  unset($_SESSION['sellercode'][$id]);
}

return header('Location: /basket');
I would use this structure:

$_SESSION['mybasket'][$id] = [
  'label' =&gt; $label,
  'code' =&gt; $code,
  'price =&gt; $price,
];


Then you can delete one item

unset($_SESSION['mybasket'][$id]);


or the complete basket

unset($_SESSION['mybasket']);


You don't need the variable loop, to count the items use

$count = count($_SESSION['mybasket']);