Unsetting Multi-Dimensional Array Session Variables
Posted: Tue Oct 14, 2008 12:02 pm
I store a user's shopping cart in an array like this:
$_SESSION['cart'][0]['any_Attribute']
$_SESSION['cart'][1]['any_Attribute']
Here's how I destroy a cart item:
if ($_GET['action'] == 'delete'){
unset($_SESSION['cart'][$_GET['number']]);
$_SESSION['cart']=array_merge($_SESSION['cart']);
}
Will unset() destroy every attribute? Say there were 2 items... deleting
item "0" and merging the cart will mean that item "1" is now item "0"... but
have all of the deleted item's attributes been completely destroyed? Since
not all items have every attribute it won't always be over-written... It has
always seemed to function properly...
Thanks,
Jacob
$_SESSION['cart'][0]['any_Attribute']
$_SESSION['cart'][1]['any_Attribute']
Here's how I destroy a cart item:
if ($_GET['action'] == 'delete'){
unset($_SESSION['cart'][$_GET['number']]);
$_SESSION['cart']=array_merge($_SESSION['cart']);
}
Will unset() destroy every attribute? Say there were 2 items... deleting
item "0" and merging the cart will mean that item "1" is now item "0"... but
have all of the deleted item's attributes been completely destroyed? Since
not all items have every attribute it won't always be over-written... It has
always seemed to function properly...
Thanks,
Jacob