I have this code to delete any idea from a cart... I need to delete two$_SESSION
.
1) $_SESSION["cart_array"]
2 $_SESSION["minicart"]
Without me adding $_SESSION["minicart"]
it does delete the $_SESSION["cart_array"]
but when i added it i got the minicart
part i got an undefined index: minicart
. So I
tried
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) && !isset($_SESSION["minicart"]) || count($_SESSION["minicart"]) < 1) {
the code above checks // If the cart session variable is not set or cart array is empty*
to the orginal if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
So
<?php
// if user wants to remove an item from cart
if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") {
// Access the array and run code to remove that array index
$key_to_remove = $_POST['index_to_remove'];
if (count($_SESSION["cart_array"]["minicart"]) <= 1) {
unset($_SESSION["cart_array"]["minicart"]);
} else {
unset($_SESSION["cart_array"]["minicart"] ["$key_to_remove"]);
sort($_SESSION["cart_array"]["minicart"]);
}
}
?>
My quesion
Looking at the tried what I am i doing wrong in the if
statement and also what am I doing wrong in the statement
to delete the ($_SESSION["cart_array"]) AND ($_SESSION["minicart"])
If this is still unclear please leave a comment and I will do my best to explain it again.