Hi I am having some problems reindexing an array.
Basically I have an array which is built when people add products to a cart. The result is below.
$bob = array(
array('quantity' => 2,'product' => 22)
array('quantity' => 1,'product' => 11)
array('quantity' => 1,'product' => 103)
array('quantity' => 1,'product' => 15)
array('quantity' => 1,'product' => 43)
array('quantity' => 2,'product' => 34)
array('quantity' => 1,'product' => 54)
array('quantity' => 1,'product' => 59));
When the products are output into the cart in html they are tagged with an increment $num ($num++). I then have a form element attatched to each product where people can remove products from their cart.
//form
if ("Remove" == $Remove) {
//remove array/product selected
unset ($bob[$num]);
//reindex the $bob array
$bob = $bob;
$b = array();
for ($t = 0; $t < sizeof ($bob); $t++)
{
if($bob[$t] != ""){
$b[] = $bob[$t];
}else{
//nothing
}
}
$bob = $b;
//then re-output $bob to html with a new $num increment
This is the above code which removes the selected item from the cart and then reindex's the array. This works fine if you pick the last item in the cart to remove. But if I have (for example) 5 items in the cart and choose to remove either 0,1,2,3 in the array count this code removes two items from the list. Can anyone see where i may be going wrong here.
I can post the link if people need to see the proble first hand.
Cheers