在php中从购物车中删除单个商品

时间:2017-10-07 23:00:20

标签: php session cart shopping

我正在尝试从cart.php中删除单个项目,它无法正常工作。我该怎么办 ?这是我的代码:

<?php
error_reporting(0);

$item_id = $_GET["item_id"];

session_start();

if(!empty($_SESSION["incart"])) {

    foreach($_SESSION["incart"] as $select => $val) {  

        unset($_SESSION["incart"]);

    }

}
?>

print_r输出

Array (
        [0] => Array ( 
            [item_id] => 100002
            [item_name] => Porsche
            [item_price] => 200
            [item_img] => porsche.jpg
            [nowdate] => 40
            [enddate] =>60
         )
)

1 个答案:

答案 0 :(得分:1)

请尝试以下代码:

public class square {
    private int sideLength; 
    private int area;

    public square( int initialLength ) {
        sideLength = initialLength;
        area = sideLength * sideLength; 
    }

    public int area() {
        return area;
    }

    public void grow() { 
        sideLength = 2 * sideLength;
    }
}