小鎮樹妖--住在樹上的妖

          To follow the path: look to the master, follow the master, walk with the master, see through the master, become the master.

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            10 Posts :: 50 Stories :: 7 Comments :: 0 Trackbacks

          <?php

          返回的數據形式如下

          Array
          (
            [汽車] => Array
              (
                [三菱] => 20
                [本田] => 500
              )

            [蛋] => Array
              (
                [雞蛋] => 20
                [鴨蛋] => 20
              )
          }

          ######################################################################################*/
          class ShopCar{
            var $carName;
            var $debug;
            /**
            @desc 新建一輛購物車.指定購物車名,如果有,將返回原來的購物車
            @param String $carName
            @param Boolean $get
            @return void
            */
            function ShopCar($carName){
              $this->carName=$carName;
              if (!isset($_SESSION[$carName])){
                $_SESSION[$carName]=array();
              }
            }
            /**
            @desc 向購物車內增加一件商品,類型,商品名,數量,插入成功返回真,否則返回假
            @param String $type
            @param String $name
            @param String $val
            @return bool
            */
            function addCar($type,$name,$val){
              if(array_key_exists($type,$_SESSION[$this->carName])){//總類別是否存在..如 汽車 有
                if (array_key_exists($name,$_SESSION[$this->carName][$type])){//分類別是否存在 如 三菱 有
                  if ($this->debug)echo "<br/>已有{$name}商品,不必增加<br/>";
                  return false;
                }else {
                  $_SESSION[$this->carName][$type][$name]=$val;
                }
              }else {
                $_SESSION[$this->carName][$type]=array($name=>$val);
              }
              return true;
            }
            /**
            @desc 編輯商品
            @param string $type
            @param string $name
            @param string $var
            @return bool
            */
            function editCar($type,$name,$var){
              if (!array_key_exists($name,$_SESSION[$this->carName][$type])){
                if ($this->debug)echo "<BR>沒有{$name}商品,修改失敗<br/>";
                return false;
              }
              $_SESSION[$this->carName][$type][$name]=$var;
              return true;
            }
            /**
            @desc 刪除類別
            @param string $type
            @return bool
            */  
            function delCarType($type){
              if (!array_key_exists($type,$_SESSION[$this->carName])){
                if ($this->debug)echo "<br/>沒有{$type}類別,刪除失敗<br/>";
                return false;
              }
              unset($_SESSION[$this->carName][$type]);
              return true;
            }
            /**
            @desc 刪除商品
            @param string $type
            @param string $name
            @return bool
            */  
            function delCarPro($type,$name){
              if (!array_key_exists($name,$_SESSION[$this->carName][$type])){
                if ($this->debug)echo "<br/>沒有{$name}商品,刪除失敗<br/>";
                return false;
              }
              unset($_SESSION[$this->carName][$type][$name]);    
              return true;
            }
            /**
            @desc 刪除此購物車
            @return bool
            */  
            function delCar(){
              session_unregister($this->carName);
            }
            /**
            @desc 獲得購物車數據
            @return array[array[]]
            */  
            function getCarData(){
              return $_SESSION[$this->carName];
            }
          }
          ?>

          posted on 2005-07-12 12:50 jacky wu 閱讀(485) 評論(0)  編輯  收藏 所屬分類: PHP
          主站蜘蛛池模板: 和硕县| 文安县| 兰坪| 肥东县| 南召县| 宜兰市| 迁安市| 霍邱县| 金湖县| 潼南县| 南江县| 民权县| 永修县| 仪征市| 凯里市| 资源县| 长宁区| 高阳县| 盐亭县| 霍山县| 错那县| 长丰县| 陇南市| 长汀县| 商南县| 土默特右旗| 孝昌县| 石柱| 深州市| 苏州市| 光山县| 新丰县| 安龙县| 蒲江县| 东城区| 乌苏市| 威宁| 沐川县| 广宁县| 兴国县| 南汇区|