I am having problem with adding items in $_SESSION variable of PHP with a custom function. so... I want to write sessions with a function like this
public function set($key, $value) {
$_SESSION[$key] = $value;
}
but every time when I call the function the array is overwritten
//$combination = "1-10"; > 1 = product_id | 10 = option_id
$this->session->set("cart", array(implode("-", $combination) => array(
"product_id" => $combination["product_id"],
"variant_id" => $combination["variant_id"],
"quantity" => 1
)));
OUTPUT
[cart] => Array
(
[1-30] => Array
(
[product_id] => 1
[variant_id] => 30
[quantity] => 1
)
)
)
This is working properly
$_SESSION["cart"][implode("-", $combination)] = array(
"product_id" => $combination["product_id"],
"variant_id" => $combination["variant_id"],
"quantity" => 1
);
OUTPUT
[cart] => Array
(
[1-30] => Array
(
[product_id] => 1
[variant_id] => 30
[quantity] => 1
)
[1-29] => Array
(
[product_id] => 1
[variant_id] => 29
[quantity] => 1
)
[1-28] => Array
(
[product_id] => 1
[variant_id] => 28
[quantity] => 1
)
)
$_SESSION["cart"][implode("-", $combination)]only adds a single array to session[cart]. How do you end up with 3 entries?