2014-01-25 73 views
0

所以,我有我的會話內部有一個「購物車」點陣這樣笨 - 未設置會話數據(USER_DATA陣列內)

Array 
(
[session_id] => 4a5a5dca22728fb0a84364eeb405b601 
[ip_address] => 127.0.0.1 
[user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; 
[last_activity] => 1303142623 
[cart] => Array([1]=1; 
       [2]=3; 
       ) 
) 

我的問題,我想取消設置車array..but內的一個ID不是整個「購物車」數據

$this->session->unset_userdata($id); //$id as in [cart][$id] 
//or even like this below 
$tmp = $this->session->userdata('cart');   
$this->session->unset_userdata($tmp[$pid]); 

我試過上面的,但它沒有做到這一點。幫幫我!

PS:我通過$ ID通過URI,可以呼應的$ id就好

========================= =========================== 更新: 感謝您的回覆,但我以某種方式解決了我的問題。我做了這樣的

$tmp = $this->session->userdata('cart');   
unset($tmp[$pid]); 
$this->session->set_userdata('cart',$tmp); 
+0

http://stackoverflow.com/questions/14561332/how-to- remove-the-single-cart-item-using-codeigniter-cart-class – sbaaaang

+0

@sbaaaang:我沒有使用CI內置的購物車類 – user2960754

回答

0

可以取消設置爲

$tmp = $this->session->userdata('cart');   
unset($tmp[$pid]); 
$this->session->set_userdata(array("cart"=>$tmp)); 
1

你可以試試這個,

$tmp = $this->session->userdata('cart'); 
unset($tmp[$id]); 
$this->session->set_userdata('cart', $tmp);