In the context of PHP and HTML interaction, what are some strategies for improving user experience when selecting multiple checkboxes for deleting items from a cart?

When selecting multiple checkboxes for deleting items from a cart, it's important to provide a clear and user-friendly interface. One strategy is to include a "Select All" checkbox that allows users to quickly select all items at once. Additionally, you can use JavaScript to dynamically update the total number of selected items and provide a confirmation message before deleting.

<?php
// Assuming you have an array of items in the cart
$cartItems = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5'];

if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['delete'])) {
    foreach ($_POST['selectedItems'] as $selectedItem) {
        // Delete selected items from the cart
        unset($cartItems[$selectedItem]);
    }
}

// Display checkboxes for each item in the cart
echo '<form method="post">';
foreach ($cartItems as $key => $item) {
    echo '<input type="checkbox" name="selectedItems[]" value="' . $key . '">' . $item . '<br>';
}
echo '<input type="submit" name="delete" value="Delete Selected Items">';
echo '</form>';
?>