/** Cart Functions **/ function add($p_id,$name,$price,$qty,$image){ if(!inCart($p_id)){ $temp['id'] = $p_id; $temp['name'] = $name; $temp['price'] = $price; $temp['image'] = $image; $temp['qty'] = $qty; $temp['sub_tot'] = $price*$qty; $_SESSION['cart'][] = $temp; $_SESSION['total'] = $_SESSION['total']+$temp['sub_tot']; $_SESSION['tot_qty'] = $_SESSION['tot_qty']+$qty; } else { update($p_id,$_SESSION['cart'][$key]['qty']+$qty); } } function inCart($p_id){ $temp = $_SESSION['cart']; if(is_array($temp) and !empty($temp)){ foreach($temp as $key => $value){ if($value['id'] == $p_id){ return true; } } } return false; } function disp(){ $temp = $_SESSION['cart']; if(is_array($_SESSION['cart'])){ echo '<ul>'; foreach($temp as $key => $value){ echo '<li>?Name '.$value['name'].' Price '.$value['price'].' x '.$value['qty'].' = '.$value['sub_tot'].'</li>'; } echo '<li>Total = '.$_SESSION['total'].' Qty = '.$_SESSION['tot_qty'].'</li>'; echo '</ul>'; } else { echo 'Empty!'; } } }