PHP ショッピング カートの実装コード_PHP チュートリアル

WBOY
リリース: 2016-07-21 15:24:09
オリジナル
1548 人が閲覧しました

ShopCar.php

コードをコピーします コードは次のとおりです:

class Shopcar
{
//Product list
public $productList=array();
/**
*
* @paramunknown_type $product 渡された商品
* @return true 商品はショッピングカートにありません
*/
public function checkProduct($product)
{
for($i=0;$iproductList);$i++ )
{
if($this->productList[$ i][' name']==$product['name'])
return $i;
}
return -1;
//カートに追加
public function add($product)
{
$i =$this ->checkProduct($product);
if($i==-1)
array_push($this->productList,$product);
else
$this->productList[$i][ 'num' ]+=$product['num'];
//削除
public function delete($product)
{
$i=$this->checkProduct($i); !=- 1)
array_splice($this->productList,$i,1);
}
//すべての製品情報を返す
public function show()
{
return $this->productList
}
}


productList.html


コードをコピー
コードは次のとおりです:


ここにタイトルを挿入

人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!