Q:

Array editing not working correctly

OK so here's my code to edit a specific entry within the array, and the array layout is below.
$counter = 0;

foreach($_SESSION['cart'] as $listitem){

    if ($listitem[0] == $_POST['product']){
        if ($listitem[1] <= $_POST['remove']){
            $remove = array($listitem[0], 0);
            $_SESSION['cart'][$counter] = $remove;
        } else {
            $result = $listitem[1] - $_POST['remove'];
            $remove = array($listitem[0], $result);
            $_SESSION['cart'][$counter] = $remove;
        }
    }

$counter = $counter++;
}

Here's my $_SESSION['Cart'] Array layout
Array( 

 - [0] => Array ( [0] => 8 [1] => 0 )
 - [1] => Array ( [0] => 10 [1] => 0 )       
 - [2] => Array ( [0] => 8 [1] => 1 )

)

Either my understanding of the array is wrong with this line of code:
$_SESSION['cart'][$counter]

Or my counter will not count: 
$counter = $counter++;

since the only value it keeps editing the first entry [0]
Can anybody see where I've went wrong?

A:

$counter = $counter++ will do nothing.
$counter++ increments the value of $counter, but evaluates to its current value (the one it had before incrementing). That way, you're setting $counter to have the value of itself, and that doesn't usually do much.
Simply do $counter++ instead.
(Additional info: there's also the pre-increment operator, ++$counter, which increments the variable and returns it new value.)

