How can PHP code be structured to handle the deletion of both music IDs and their corresponding prices from a shopping cart?

To handle the deletion of both music IDs and their corresponding prices from a shopping cart in PHP, you can use an array to store the music IDs and their prices. When deleting an item from the cart, you can remove the corresponding ID and price from the array.

// Sample code to handle deletion of music IDs and prices from a shopping cart

// Initialize the shopping cart array with music IDs and prices
$shoppingCart = [
    ['id' => 1, 'price' => 10.99],
    ['id' => 2, 'price' => 15.99],
    ['id' => 3, 'price' => 9.99]
];

// Function to delete item from shopping cart based on ID
function deleteItemFromCart($id, &$cart) {
    foreach ($cart as $key => $item) {
        if ($item['id'] == $id) {
            unset($cart[$key]);
            break;
        }
    }
}

// Delete item with ID 2 from the shopping cart
deleteItemFromCart(2, $shoppingCart);

// Display updated shopping cart
print_r($shoppingCart);