I'm building a shopping cart and I'm using sessions to save the cart products. The array structure that saves the items is as follows:
$_SESSION['carrinho'][ID_DO_PRODUTO;TAMANHO_SE_HOUVER] => QUANTIDADE
An example of items in the shopping cart would be:
$_SESSION['carrinho']['156;GG'] => 1,
$_SESSION['carrinho']['876;PP'] => 9,
$_SESSION['carrinho']['65;'] => 5,
The last item in the above list is one size, while the others are GG and PP respectively. However I need to add the total amount of items in the cart. I know the array_sum, but the indexes of the array are dynamic. I already thought about using the foreach, but for me it looks more ugly than my gabiarra implementation.