会话对于产品
$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
}
答案 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"]);
?>