php - Add another dimension into array cart -


i have shopping cart, works fine, store type of goods (for example color, size, etc.).

here function gets items shopping cart

public static function getcart() {         if((isset($_session['cart'])) && count($_session['cart'])>0) {             $ids = "";             foreach($_session['cart'] $id => $quantity) {                 $ids = $ids . $id . ",";             }              $ids = rtrim($ids, ',');              $dotaz = dibi::fetchall("select * eshop_products idproduct in ({$ids})");             return $dotaz;         } else {             //do nothing         }     } 

and function adds items shopping cart

public static function addtocart($data) {          $id = $data['id'];          $quantity = $data['qty'];          $varianta = $data['varianty']; //this need add session array           if(!isset($_session['cart'])) {             $_session['cart'] = array();         }           if(isset($_session['cart'][$id])) {             $_session['cart'][$id] += $quantity;         } else {             $_session['cart'][$id] = $quantity;         }        } 

is there easy way that? googled tutorials, still no success.

thank you.

maybe hint you:

$id = $data['id'];  $quantity = $data['qty'];  $varianta = $data['varianty']; //this need add session array  $cart = array();  array_push($cart, array(   'id' => $id,   'quantity' => $quantity,   'varianta' => $varianta )); 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -