What are the best practices for assigning unique identifiers to items in a PHP shopping cart to avoid index confusion and potential errors?

When assigning unique identifiers to items in a PHP shopping cart, it is important to ensure that each identifier is truly unique to avoid index confusion and potential errors. One common approach is to use a combination of the item's ID and a timestamp to create a unique identifier. This helps prevent duplicate identifiers and ensures each item is uniquely identified in the cart.

// Generate a unique identifier for each item in the shopping cart
$unique_id = $item_id . '_' . time();