function getProductQuantity($productId) { // API call to retrieve product info from database or API $product = getProductInfo($productId); return $product['quantity']; }
function getCartTotalQuantity($cart) { $totalQuantity = 0; foreach($cart as $item) { $totalQuantity += getProductQuantity($item['id']) * $item['quantity']; } return $totalQuantity; }In this example, `cart` is an array of items in the shopping cart, where each item contains the product ID and quantity. The function uses `getProductQuantity()` to retrieve the quantity of each product in the cart and calculates the total quantity across all items.