deleting elements from array
Posted: Thu Jun 30, 2005 12:53 pm
I am using an array to track a users shopping cart. My array know how is a little lackin, I know.
So I've got it working fine, except for deleting items. I can get it to delete the data with unset, but there is still an empty element within the array. I'd like empty elements to begone, and the numbers to re-index. I know this is over coding, and I should use a loop somehow, but I'm a newb.
Anyway heres the code
Thanks in advance!
So I've got it working fine, except for deleting items. I can get it to delete the data with unset, but there is still an empty element within the array. I'd like empty elements to begone, and the numbers to re-index. I know this is over coding, and I should use a loop somehow, but I'm a newb.
Anyway heres the code
Code: Select all
unset($cart[$r]["style"]);
$r++;
unset($cart[$r]["color"]);
$r++;
unset($cart[$r]["size"]);
$r++;
$p = $cart[$r]["price_ea"];
unset($cart[$r]["price_ea"]);
$r++;
$num_items -= $cart[$r]["qty"];
$total_price -=$cart[$r]["qty"]*$p;
unset($cart[$r]["qty"]);