Forum Moderators: coopster
$cart[] = array('sizeid'=>$sizeid, 'photoid'=>$photoid,'photopath'=>$photopath,'size'=>$size,'price'=>$price,'quantity'=>$quantity);
$totpricearr[] = $price; i can then output my cart...
foreach ($cart as $key => $v) {
output cart data the problem i have is quantity - if the user enters 2 in the quantity box it correctly adds this to the cart.. however if the user adds the item once, and then adds it again the item shows up twice in the cart rather than merging the values.
how can i merge it if the same 'sizeid'=>$sizeid, 'photoid'=>$photoid are found in the array more than once?
pseudo..
if in cart array sizeid and photoid both found on same row - add to quantity and remove one of the rows
thanks!
$cart[] = array(etc)
you could consider
if($cart["$uniquelyIdentifyingid"]){
$cart["$uniquelyIdentifyingid"] = array(etc,quantity=>($quantity+$additionalQuantity));
}else{
$cart["$uniquelyIdentifyingId"] = array(etc,quantity=>$quantity);
}
This is pseudocode that, for an item that's already been added to the cart before, simply increments the quantity.
$cart[] = array('sizeid'=>$sizeid,'photoid'=>$photoid,'photopath'=>$photopath,'size'=>$size,'price'=>$price,'quantity'=>$quantity); i need to run a foreach loop and if photoid and sizeid are already present i need to increase the quantity and remove the duplicate values
can anbody help? thanks!