What are the common pitfalls when using PHP arrays in a session for a shopping cart functionality?

Common pitfalls when using PHP arrays in a session for a shopping cart functionality include not properly serializing and unserializing the array data when storing and retrieving it from the session. To avoid this issue, make sure to serialize the array before storing it in the session and unserialize it when retrieving it.

// Storing the shopping cart array in the session
$_SESSION['cart'] = serialize($cart);

// Retrieving the shopping cart array from the session
$cart = unserialize($_SESSION['cart']);