Hi Ladies/Gents/Other
I'm having issues with nested arrays, I need to set an array key by variable but whenever I do I get an error "invalid offset in XXXXX"
here is the code causing the problem
can someone please point out what I'm doing wrong?
Thank you in advance
I'm having issues with nested arrays, I need to set an array key by variable but whenever I do I get an error "invalid offset in XXXXX"
here is the code causing the problem
Code:
<?php
class cart{
function add($prod_id,$qty,$price) {
$prod_id=array();
if (!isset ($_SESSION['cart'])){
session_start();
$_SESSION['cart']=array($prod_id);
}
if (isset ($_SESSION['cart'][$prod_id])){
$_SESSION['cart'][$prod_id]['qty'] =+ 1;
}
else{
$_SESSION['cart'][$prod_id]=$prod_id;
$_SESSION['cart'][$prod_id]['qty']=1;
$_SESSION['cart'][$prod_id]['price']=$price;
}
print_r($_SESSION['cart'][$prod_id$]);
}
};
$cart = new cart;
$cart -> add('jfkd',2,22.50);
Thank you in advance
Comment