CODE
<?php
if(!empty($_POST["delete"]))
{
for($i=0;$i<$_SESSION["items_in_cart"];$i++)
{
if($_POST["deleteme".$i]==$i)
{
for($j=$i;$j<$_SESSION["items_in_cart"]-1;$j++)
{
$_SESSION["item"][$j]["ID"]=$_SESSION["item"][$j+1]["ID"];
$_SESSION["item"][$j]["size"]=$_SESSION["item"][$j+1]["size"];
$_SESSION["item"][$j]["number"]=$_SESSION["item"][$j+1]["number"];
}
$_SESSION["items_in_cart"]--;
}
}
}
?>
I've been testing it with 3 items in the array. It works correctly if I delete the first item. If I delete the second item, however, it actually deletes the first and third, leaving only the second. And if I delete the third item, it actually deletes the second item. I haven't even tried deleting more than one at a time yet since I'm having enough problems with just one at a time.
I can't figure out why it is doing this. I have been very careful not to mix up $i and $j. I'm pretty sure that the second for-loop's terminating condition has to be one less than the first, because it's going to set something equal to $j+1 and it would otherwise read out of the array bounds.
EDIT: Just for clarification... $_POST["delete"] refers to the name of the submit button that deletes items checked. $_POST["deleteme".$i] refers to the checkboxes which are created by a for-loop and assigned names like deleteme0, deleteme1, etc, and values are simply 0, 1, etc.