public function history($g){
//判断session里有没有history $history=session('history');//此处用了tp框架 if(empty($history)){ $history=array(); }
//取出重复浏览的商品只保留最新的 if( isset($history[$g['goods_id']])){ unset($history[$g['goods_id']]); } $row=array(); $row['thumb_img']=$g['thumb_img']; $row['shop_price']=$g['shop_price']; $row['goods_name']=$g['goods_name']; $history[$g['goods_id']]=$row;
//保证只有6条历史记录 if(count($history)>6){ $key=key($history); unset($history[$key]); }
//储存在session里 session('history',$history); }