遇到一个有意思的问题,不知道怎么说,大家进来看下吧
先看代码再说吧:
$catid = $_GET['id'];<br /> if( !isset( $_COOKIE[ $cookie_name ] ) ){<br /> $cart_ary = array();<br /> $cart_ary['cart'] = array();<br /> $cart_ary['item_num'] = 0;<br /> $cart_ary['total_price'] = 0.00;<br /> setcookie( $cookie_name,json_encode( $cart_ary ),time()+(7*24*60*60) );<br /> }<br /> //第一次获取不到值,所以需要抑制第一次报错<br /> $cart_ary = json_decode( str_replace( "\\","",@$_COOKIE[ $cookie_name ] ),true );<br /> if( isset( $cart_ary['cart'][ $catid ] ) ){<br /> $cart_ary['cart'][ $catid ]++ ;<br /> }else{<br /> $cart_ary['cart'][ $catid ] = 1;<br /> }<br /> $cart_ary['item_num'] = count_cart_item_num( $cart_ary['cart'] );<br /> $cart_ary['total_price'] = count_cart_total_price( $cart_ary['cart'] );<br /> setcookie( $cookie_name,json_encode( $cart_ary ),time()+(7*24*60*60) );
str_replace( "\\","",@$_COOKIE[ $cookie_name ] )
$catid = $_GET['id'];
if( !isset( $_COOKIE[ $cookie_name ] ) ){
$cart_ary = array();
$cart_ary['cart'] = array();
$cart_ary['item_num'] = 0;
$cart_ary['total_price'] = 0.00;
setcookie( $cookie_name,json_encode( $cart_ary ),time()+(7*24*60*60) );
}else {
$cart_ary = json_decode( str_replace( "\\","",@$_COOKIE[ $cookie_name ] ),true );
if( isset( $cart_ary['cart'][ $catid ] ) ){
$cart_ary['cart'][ $catid ]++ ;
}else{
$cart_ary['cart'][ $catid ] = 1;
}
$cart_ary['item_num'] = count_cart_item_num( $cart_ary['cart'] );
$cart_ary['total_price'] = count_cart_total_price( $cart_ary['cart'] );
setcookie( $cookie_name,json_encode( $cart_ary ),time()+(7*24*60*60) );
}