2012-11-15 41 views
0

上午我使用的是codeigniter購物車庫,但現在客戶希望用戶一次只能從一個類別簽出物品,因爲他們的付款網關存在一些問題。 當前網站對所有類別都有一個結帳邏輯。 當用戶添加一個項目到車,我有這樣的檢查購物車的物品是否具有相同的屬性

Array 
(
    [d8df18561040f3d9bd9868f5c5aaa7c2] => Array 
     (
      [rowid] => d8df18561040f3d9bd9868f5c5aaa7c2 
      [id] => MYU_SC1 
      [qty] => 1 
      [price] => 500 
      [name] => WAEC Scratch Card 
      [service_image] => assets/img/waec.jpg 
      [service_category] => scratch_cards 
      [subtotal] => 500 
     ) 

    [99483fe03da62c9e98ce71232998f447] => Array 
     (
      [rowid] => 99483fe03da62c9e98ce71232998f447 
      [options] => Array 
       (
        [size] => 36 
        [colour] => N/A 
       ) 

      [id] => 80433426a546064bf5f8d09a6e7fdabc 
      [qty] => 1 
      [price] => 5000 
      [name] => Green Vee Jeans 
      [service_image] => http://localhost/myunivacity/uploads/apparels/IMG_0425.JPG 
      [service_category] => apparels 
      [subtotal] => 5000 
     ) 

) 

數組如何我做的檢查是否在購物車中的項目有「service_category」元素相同的值?感謝您的幫助

回答

0

你可以像這樣的東西去:

<?php 

$categories = array(); 

foreach($this->cart->contents() as $cart_item) { 
    if(!isSet($categories[$cart_item["service_category"]]) { 
     $categories[$cart_item["service_category"]] = 1;   
    } 
    else { 
     $categories[$cart_item["service_category"]]++; 
    } 
} 

print_r($categories); 

?> 

這填補了一個數組,每個

分類計數
相關問題