Please check the following code below i am trying to achieve a Session based Cart system for my site:
This is what happens when i post the form:
session_start();
if (isset($_POST['addtocart'])):
$item = array(
'package' => $_POST['item_name'],
'amount' => $_POST['amount']
);
$_SESSION['cart'][] = $item;
endif;
Then the data is like this:
array(2) {
[0]=>;
array(2) {
["package"]=>;
string(42) "Bronze (Division V) ->; Bronze (Division V)"
["amount"]=>;
string(1) "0"
}
[1]=>;
array(2) {
["package"]=>;
string(46) "Bronze (Division V) ->; Challenger (Challenger)"
["amount"]=>;
string(4) "1666"
}
}
and i am trying to display data like this:
foreach ($_SESSION['cart'] as $item):
echo $item->package;
endforeach;
The result is nothing so what did i do wrong here?