Hi all,
My first post here - I'm sure I'll find a lot of helpful advice and people here.
At the moment I'm struggling with performing some calculations on array values.
What I'm trying to do is get some values from an array that holds shopping cart details than add them together but only for certain items.
Say I have an array that has 4 entries:
[0]([product_id] => 100 [quantity] =>1)
[1]([product_id] => 104 [quantity] =>3)
[2]([product_id] => 117 [quantity] =>4)
[3]([product_id] => 100 [quantity] =>2)
and a variable that holds a pre-determined value:
$prod_id = 100;
I want to get all the quantities where the product id is equal to the variable value, so in this case it would be 1 and 2, then i want to total these values so 1+2=3
The final value i am aiming to get would be 3 in this case.
I currently have a loop which accesses the array then creates an array of of the product id's:
for($i=0;$i<=count($SESSION['shoppingCart']);$i++) {
$new_array = array($SESSION['shoppingCart'][$i]['product_id']);
}
What I'm struggling with is getting only the array info where the product id is equal to $prod_id.
Can anyone help or point me in the right direction?
Many thanks,
Steve