Multidimensional array in php SESSION

前端 未结 2 808
北恋
北恋 2020-12-08 18:12

I am having problem with updating an array element with in $_SESSION variable of PHP. This is the basic structure:

$product = array();
$product[         


        
2条回答
  •  Happy的楠姐
    2020-12-08 18:35

    this not best answers for u...but hope can help u guys im not expert coders, and just learn coding in this forum ^,^ .You must always trying to solved. for more example hope can help to update value quantity:

     $id, 
        'nm_produk' => 'hoodie', 
        'img_produk' => 'images/produk/hodie.jpg', 
        'harga_produk' => '20', 
        'qty' => '2' 
        );
        //if not empty
        if(!empty($_SESSION['cart']))
        {    
            //and if session cart same 
            if(isset($_SESSION['cart'][$id]) == $id) {
                $_SESSION['cart'][$id]['qty']++;
            } else { 
                //if not same put new storing
                $_SESSION['cart'][$id] = $newitem;
            }
        } else  {
            $_SESSION['cart'] = array();
            $_SESSION['cart'][$id] = $newitem;
        }
    } 
    ?>
    

提交回复
热议问题