开发者

overwriting a part of a session

开发者 https://www.devze.com 2023-01-13 20:03 出处:网络
i have a session looking like this: array(1) { [31]=> array(10) { [\"aantal\"]=> int(1) [\"id\"]=>

i have a session looking like this:

        array(1) {
  [31]=>
  array(10) {
    ["aantal"]=>
    int(1)
    ["id"]=>
    string(2) "31"
    ["filmtitel"]=>
    string(16) "2_fast_2_furious"
    ["film_id"]=>
    string(1) "1"
    ["zaal_id"]=>
    string(1) "1"
    ["dag"]=>
    string(8) "woensdag"
    ["zaaltitel"]=>
    string(6) "zaal 1"
    ["tijdstip"]=>
    string(8) "17:30:00"
    ["stoeltjes"]=>
    array(3) {
      [0]=>
      string(2) "20"
      [1]=>
      string(2) "21"
      [2]=>
      string(2) "22"
    }
    ["aantalStoeltjes"]=>
    string(3) "150"
  }
}

my question is, how can i overwrite the content of ["stoeltjes"]?

when i do unset($_SESSION['addToCart'][$id]["stoeltjes"]);

then ["stoeltjes"]gets deleted but when i add other values they get put in an extra arra开发者_开发技巧y inside the stoeltjes array.

I assign the new values ass following: $_SESSION["addToCart"][$id]["stoeltjes"][] = $seats;


$_SESSION['addToCart'][$id]["stoeltjes"] = "new value";

should do it.


Lets say you want to put 25 in ["stoeltjes"] then, do it like this:

 $_SESSION['addToCart'][$id]["stoeltjes"] = 25;


the extra [] tells the code that you want a new array element in your variable.

doing this:

$_SESSION["addToCart"][$id]["stoeltjes"][] = "new value";
$_SESSION["addToCart"][$id]["stoeltjes"][] = "new value";
$_SESSION["addToCart"][$id]["stoeltjes"][] = "new value";

is equivalent of doing this:

$_SESSION["addToCart"][$id]["stoeltjes"][0] = "new value";
$_SESSION["addToCart"][$id]["stoeltjes"][1] = "new value";
$_SESSION["addToCart"][$id]["stoeltjes"][2] = "new value";
0

精彩评论

暂无评论...
验证码 换一张
取 消