How can the use of unique IDs for each article in a Warenkorb session prevent issues with deleting specific articles?

Issue: When deleting specific articles from a Warenkorb session, it can be challenging to accurately identify and remove the correct article without unique identifiers. By assigning a unique ID to each article in the session, we can easily target and delete the specific article without affecting others.

// Assigning unique IDs to articles in the Warenkorb session
$warenkorb = $_SESSION['warenkorb'];

foreach($warenkorb as $key => $article) {
    $warenkorb[$key]['id'] = uniqid();
}

$_SESSION['warenkorb'] = $warenkorb;

// Deleting a specific article using its unique ID
$article_id_to_delete = $_POST['article_id'];

foreach($warenkorb as $key => $article) {
    if($article['id'] === $article_id_to_delete) {
        unset($warenkorb[$key]);
        break;
    }
}

$_SESSION['warenkorb'] = $warenkorb;