How can the issue of functions like "Edit Item Quantity" and "Delete Item" affecting all items in the shopping cart be resolved in PHP?

The issue of functions like "Edit Item Quantity" and "Delete Item" affecting all items in the shopping cart can be resolved by uniquely identifying each item in the cart using item IDs. By passing the item ID along with the action (edit/delete) to the PHP script, we can target specific items for modification.

// Assuming we have an array $cart containing items with unique IDs
if(isset($_POST['item_id']) && isset($_POST['action'])) {
    $item_id = $_POST['item_id'];
    
    // Edit Item Quantity
    if($_POST['action'] == 'edit') {
        $new_quantity = $_POST['new_quantity'];
        $cart[$item_id]['quantity'] = $new_quantity;
    }
    
    // Delete Item
    if($_POST['action'] == 'delete') {
        unset($cart[$item_id]);
    }
}