修改会话变量(购物车)

时间:2014-09-01 09:22:26

标签: php html mysql session session-variables

会话对于产品

$product = array(array('name'=>$resname, 'code'=>$product_code, 'qty'=>$product_qty, 'price'=>$resprice, 'sizes'=>$sizes ,'colourcode'=>$colourcode , 'availability'=>$availability));
$_SESSION["products"] = $product;

    name="product1";
    code="123";
    ...
    availability=1;

现在我想修改会话中特定产品的可用性,仅使用进行每个循环

foreach ($_SESSION["products"] as $cart_itm){ 
$cart_itm["code"];
$cart_itm["availability"];
//code to  modify availability for current product  
}

1 个答案:

答案 0 :(得分:0)

你在寻找吗?

<?php
    session_start();
    $product = array(array('name'=>'resname', 'code'=>'product_code', 'qty'=>'product_qty', 'price'=>'resprice', 'sizes'=>'sizes' ,'colourcode'=>'colourcode' , 'availability'=>'availability'));
    $newProduct=$product;// new step
    $_SESSION["products"] = $newProduct;


    foreach ($_SESSION["products"] as $cart_itm){ 
    $newProduct[0]["availability"]='modifiedavailability';
    }

   //or To all Keys

   // foreach ($_SESSION["products"] as $cart_itm => $value){ 
    //$cart_itm["code"];
    //$newProduct[$cart_itm]["availability"]='modavaila';
   //}
    $_SESSION["products"] = $newProduct;
    print_r($_SESSION["products"]);
?>