慕码人8056858
简单点来说,操作SESSION可以视为操作数组一样;楼主说session保存购物车信息如何操作,demo如下:// 假如SESSION里的购物车商品保存的是这种数据形式$_SESSION['cart']['goods'] = [ 'goods_id' => [ 'goods_name' => 'goods_name', 'price' => 'price', 'spec' => 'spec', 'num' => 'num' ], '1' => [ 'goods_name' => '橙子', 'price' => '15.00', 'spec' => '脐橙;', 'num' => '10' ], '2' => [ 'goods_name' => '苹果', 'price' => '10.00', 'spec' => '红苹果;', 'num' => '5' ]];/** * 存储商品信息到购物车 * 1、先取出SESSION购物车里的商品数据 * 2、生成新的商品数据 * 3、保存到SESSION */$session_goods = $_SESSION['cart']['goods'];$session_goods[11] = [ 'goods_name' => 'T恤', 'price' => '69.00', 'spec' => '颜色:红色;品牌:以纯;', 'num' => '1'];$_SESSION['cart']['goods'] = $session_goods;/** * 购物车里商品ID为1的商品需要删除 * 并更新保存到SESSION */unset($goods['1']);$_SESSION['cart']['goods'] = $goods;